Class Data Structure
A class is a data structure that includes data members, function members, and nested types for encapsulation.
Data Member contained in the class
Constructor, destructor, constant, field, attribute, method, event, Delegate, class, structure, interface, Indexer
Data members can be static members, that is, they are related to the entire class or instance members, that is, they are related to objects.
Fields are class-related variables. They are declared in the same way as declared variables. fields are declared in the class, and variables are declared in the main function and method.
Instance
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
namespace _ 3_classmember
{< br> class Program
{< br> static void main (string [] ARGs)
{< br> Student = new student ();
console. writeline ("Name: {0}", student. _ name);
console. writeline ("Age: {0}", student. _ age);
// we can see that the access constant must be accessed by the student class. The constant belongs to the class member, and the field belongs to the member of the instantiated object.
console. writeline ("Gender: {0}", student. _ sex);
console. readkey ();
}< BR >}
Class student
{
// Declare Fields
Public String _ name = "James ";
Public int _ age = 25;
// Declare a constant
Public const string _ sex = "male ";
}
}
Running Effect