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

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();
主站蜘蛛池模板: 青铜峡市| 宜良县| 堆龙德庆县| 沈丘县| 尼木县| 基隆市| 汾西县| 昌邑市| 衡东县| 成武县| 定结县| 秦安县| 酉阳| 涿州市| 阜平县| 横山县| 綦江县| 弋阳县| 商南县| 嘉定区| 宕昌县| 衡东县| 斗六市| 惠东县| 武威市| 克什克腾旗| 武功县| 民权县| 磴口县| 宁阳县| 裕民县| 饶阳县| 昆山市| 弥渡县| 呼伦贝尔市| 建湖县| 新邵县| 德昌县| 八宿县| 弥勒县| 临沧市|