官术网_书友最值得收藏!

How to create objects

In C#, to create an object of a class, you have to use the new keyword. Let's look at an example of an object:

Customer customer1 = new Customer();

Here, we started by writing Customer, which is the name of the class. This represents the type of the object. After that, we gave the name of the object, which in this case is customer1. You can give any name to that object. For example, if the customer is Mr. Jones, we could name the object jackJones. After the object name, we then inserted an equals sign (=), which means that we are assigning a value to the customer1 object. After that, we entered a keyword called new, which is a special keyword that tells the compiler to create a new object of the class that is given next to it. Here, we gave Customer again with () next to it. When we place Customer(), we are actually calling the constructor of that class. We will talk about constructors in subsequent chapters.

We can create jackJones by using the following code:

Customer jackJones = new Customer();
主站蜘蛛池模板: 思茅市| 磴口县| 平安县| 客服| 大方县| 宜阳县| 车险| 栾城县| 宁明县| 和平区| 广水市| 哈巴河县| 修武县| 嘉黎县| 房产| 连江县| 南川市| 曲松县| 关岭| 六安市| 中方县| 米易县| 康平县| 芜湖县| 乌审旗| 隆化县| 南皮县| 北川| 印江| 浪卡子县| 宣汉县| 孝昌县| 庐江县| 阿巴嘎旗| 甘肃省| 江孜县| 南通市| 方城县| 宣化县| 咸丰县| 抚顺市|