Topic description
class declaration. (console application)
using System; using System.Collections.Generic; using System.Linq; using System.Text; Declaration of namespace class { class Program { static void Main(string[] args) { //To instantiate a class is to assign the class to an object Clerk zsClerk = new Clerk(); zsClerk._name = "Zhang San"; zsClerk._gender = Gender.男; zsClerk._age = 25; zsClerk._department = "Department of Manpower"; zsClerk._workYears = 5; //call non-static method zsClerk.Write(); // instantiate Clerk IsClerk = new Clerk(); IsClerk._name = "Li Si"; IsClerk._gender = Gender.女; IsClerk._age = 35; IsClerk._department = "Finance Department"; IsClerk._workYears = 3; IsClerk.Write(); } } }
(declare a class) Solution Explorer → Right-click on the project name → Add → New Item → Class
using System; using System.Collections.Generic; using System.Linq; using System.Text; Declaration of namespace class { public enum Gender { male, Female } class Clerk { //The method can store fields, properties, and methods public string _name;//Field, naming convention, _camelCase //The field can store multiple values, the variable can only store one value, and the field is used to store data public Gender _gender; public int _age; public string _department; public int _workYears; public void Write() { Console.WriteLine("My name is {0}, I am from {1}, I am {2} years old, I work at {3}, I have worked for {4} years",this._name,this._gender,this ._age,this._department,this._workYears);//The keyword this represents the current object that has been instantiated } } }