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

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();
主站蜘蛛池模板: 饶平县| 通山县| 迭部县| 福贡县| 洪洞县| 寿宁县| 开封市| 安龙县| 隆德县| 绥芬河市| 黄龙县| 辽阳县| 延津县| 荔波县| 忻州市| 衢州市| 淮南市| 苍山县| 辽源市| 许昌市| 长兴县| 正镶白旗| 密云县| 大悟县| 达拉特旗| 抚宁县| 子长县| 河池市| 江都市| 肇东市| 霍林郭勒市| 天津市| 姚安县| 沂南县| 汉川市| 盘锦市| 色达县| 宁安市| 江陵县| 石楼县| 古蔺县|