- Hands-On Object:Oriented Programming with C#
- Raihan Taher
- 196字
- 2021-07-02 12:44:41
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();
- HTML5+CSS3+JavaScript從入門到精通:上冊(微課精編版·第2版)
- DevOps with Kubernetes
- Getting started with Google Guava
- 基于Java技術(shù)的Web應(yīng)用開發(fā)
- Spring Boot企業(yè)級項目開發(fā)實戰(zhàn)
- Learning Raspbian
- Learning Splunk Web Framework
- Python趣味編程與精彩實例
- 超簡單:Photoshop+JavaScript+Python智能修圖與圖像自動化處理
- Go語言入門經(jīng)典
- JavaScript編程精解(原書第2版)
- Elasticsearch Blueprints
- Mapping with ArcGIS Pro
- Koa與Node.js開發(fā)實戰(zhàn)
- Mastering ArcGIS Server Development with JavaScript