Thinking in C# phần 2
➤ Gửi thông báo lỗi ⚠️ Báo cáo tài liệu vi phạmNội dung chi tiết: Thinking in C# phần 2
Thinking in C# phần 2
object (using new, as seen earlier) in a special function called a constructor (described fully in chapter 4). If it is a primitive type you can initi Thinking in C# phần 2 ialize it directly at the point of definition in the class. (As you’ll see later, references can also be initialized at the point of definition.)Each object keeps its own storage for its data members; the data members are not shared among objects Here is an example of a class with some data members: Thinking in C# phần 2 public class Dataonly {public int 1;public float f;public bool b;private string s;}This class doesn't do anything, but you can create an object:DataOnThinking in C# phần 2
ly d - new DataOnlyO;Both the classname and the fields except s are preceded by the word public. Ulis means that they are visible to all other objectsobject (using new, as seen earlier) in a special function called a constructor (described fully in chapter 4). If it is a primitive type you can initi Thinking in C# phần 2 ng the name of the object reference, followed by a period (dot), followed by the name of the member inside the object:objectReferer.ee .memberFor example:d.l 47;d.f - 1.1;d.b false;However, the string s field is marked private and is therefore not visible to any other object (later, well discuss o Thinking in C# phần 2 ther occess modifiers that are intermediate between public and private). If you tried to write:I d.s "asdf";you would get a compile error Data hidingThinking in C# phần 2
seems inconvenient at first, but is so helpful in a program of any size that the default visibility of fields is private.It is also possible that youobject (using new, as seen earlier) in a special function called a constructor (described fully in chapter 4). If it is a primitive type you can initi Thinking in C# phần 2 ank.capacity 100;5ỐThinking in c*WWW MindView.netThe DataOnly class cannot do much of anything except hold data, because It has no member functions (methods). To understand how those work, you must first understand arguments and return values, which Will be described shortly.Default values for valu Thinking in C# phần 2 e typesWhen a value type IS a member of a class, It is guaranteed to get a default value if you do not initialize it:Value typeSize in bitsDefaultboolThinking in C# phần 2
4FALSEchar8‘\uoooo’ (null)byte, sbyte8(byte)oshort, ushort8(short)oint. uint320long, ulong64oLfloat8o.ofdouble64o.oddecimal960object (using new, as seen earlier) in a special function called a constructor (described fully in chapter 4). If it is a primitive type you can initiobject (using new, as seen earlier) in a special function called a constructor (described fully in chapter 4). If it is a primitive type you can initiGọi ngay
Chat zalo
Facebook