当前位置:网站首页>Learning record -- memo on constructors and attributes in C
Learning record -- memo on constructors and attributes in C
2022-06-23 02:52:00 【MrLi001】
First, there are two classes , Respectively Program Classes and Customer Class as a reference . among Program Store the main function in , Customer Stored in class customer Properties of .
Customer Class
class Customer
{
private string name;
public string address;
private int age;
private string creatTime;
}stay Program Instantiation in Customer Class object
Stabilization mode ① Constructors , All attributes
Customer Constructors
public Customer(string name, string address, int age, string creatTime)// Constructors , It can be understood as written initialization
{
this.name = name;
this.address = address;
this.age = age;
this.creatTime = creatTime;
}stay Program In the implementation of
class Program
{
static void Main(string[] args)
{
Customer cusm = new Customer(" Li Si "," Here, there ",55,"2000");
}
}Stabilization mode ②( For attribute )
Customer Medium set、get Method , With age Attribute as an example
public void SetAge(int age)
{
this.age = age;//this.age Represents the... Defined in this class , hinder age Represents the parameters in this method
}
public int GetAge()
{
return age;
}stay Program In the implementation of
class Program
{
static void Main(string[] args)
{
Customer cusm = new Customer(" Li Si "," Here, there ",55,"2000");
cusm.SetAge(8);
}
}Stabilization mode ③( For attribute )
Customer Medium set、get Method simple version , With age Attribute as an example
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}stay Program In the implementation of
class Program
{
static void Main(string[] args)
{
Customer cusm = new Customer(" Li Si "," Here, there ",55,"2000");
cusm.Age=18;
}
}④ For Customer Properties not defined in , You can create attributes directly and automatically
public string Detail { get; set; }stay Program In the implementation of
class Program
{
static void Main(string[] args)
{
Customer cusm = new Customer(" Li Si "," Here, there ",55,"2000");
cusm.Detail = " Here are the details about Li Si ";
}
}边栏推荐
- Im web demo invite end hang up error avoidance
- Direct collection - super easy to use domestic color matching website
- Why do I use index, query or slow?
- Zoom/skype/ nailing / live broadcast / conference / online video real-time subtitle generation and translation, simultaneous interpretation
- How does the easyplayer streaming video player set up tiling?
- Handlebars dynamic adjustment
- Wechat applet camera compressed image is Base64
- Goframe framework (RK boot): Based on cloud native environment, distinguish configuration files (config)
- [data preparation and Feature Engineering] perceived data
- Detailed explanation of online reputation management
猜你喜欢

Spark broadcast variables and accumulators (cases attached)

Microservice Optimization: internal communication of microservices using grpc

Unity official case nightmare shooter development summary < I > realization of the role's attack function

Understand GB, gbdt and xgboost step by step

5. concept of ruler method

Log a log4j2 vulnerability handling

Soft exam information system project manager_ Information system comprehensive testing and management - Senior Information System Project Manager of soft test 027

Mongodb aggregate query implements multi table associated query, type conversion, and returns specified parameters.

6. template for integer and real number dichotomy

My good brother gave me a difficult problem: retry mechanism
随机推荐
Salesforce fileUpload (III) how to display uploaded images
OVS port traffic statistics practice
No error is reported when using the Gorm framework to create a table, but the data cannot be inserted successfully
Aiot application innovation competition -- I am the master of my project, and use gn+ninja to complete the system construction (vscode Development)
WM view of commodity master data in SAP retail preliminary level
How does the easyplayer streaming video player set up tiling?
Add other view components to the audio and video components of the applet
A bit about the state machine (FSM SMR DFSM)
EDI project cases of customers in medical device industry
Record a penetration caused by log4j
SetTimeout and setinterval execution time
862. triple sorting
Why do I use index, query or slow?
PNAs: power spectrum shows obvious bold resting state time process in white matter
How to gracefully solve the problem of platform font adaptation
Applet control version update best practices
A penetration of an internal self built shooting range
Deep analysis of time complexity
Handlebars dynamic adjustment
Docker builds MySQL master-slave