Contenido del Curso
C# Beyond Basics
C# Beyond Basics
Defining Classes
The syntax for defining a basic class is the following:
index
class nameOfClass { public datatype fieldName1; public datatype fieldName2; public datatype fieldName3; ... }
For example, a class for storing data about houses:
index
using System; class House { public string ownerName; public float landArea; public string country; public string state; public string city; public string streetAddress; } public class ConsoleApp { public static void Main(string[] args) { Console.WriteLine ("Nothing here yet."); } }
The above code contains a class that defines a blueprint for a 'House' object, representing a house that can store the ownerName, land area, country, state, city and street address.
Using objects is very convenient as we can group related information to form a Class and neatly create multiple instances of that data if needed. Using the House
class we can easily store and access data for thousands of houses.
¡Gracias por tus comentarios!