在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
要点摘要:
The Differences between classes and structs
Properties 1) read-only and write-only properties: create a read-only property by simply omitting the set accessor from the property definition; create a write-only property by omitting the get accessor. 2)access modifers for properties: e.g. (get is public and set is private) public string Name { get { return _name; } private set { _name = value; } } 3) auto implimented properties
Static Constructors a static no - parameter constructor for a class will be executed only once, as opposed to the constructors written so far, which are e.g. { static MyClass() { //initialization code } //rest of the class definition } Notice: i) the static constructor does not have any access modifiers. It ’ s never called by any other C# code, but always by the .NET runtime when the class is loaded ii) the static constructor can never take any parameters, and there can be only one static constructor for a class. iii) a static constructor can access only static members, not instance members, of the class
constants don ’ t necessarily meet all requirements.On occasion, you may have some variable whose value shouldn ’ t be changed, but where the value is not known until runtime. C# provides another type of variable that is useful in this scenario: the readonly field
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论