Visceral Guide to C # 3.0! This is not meant to give you enough information to be useful to encode - but you can pretend you know what you're talking geek in the right company. More seriously, it will give a very rough to give some context, if you decide to further investigate a particular feature.
Each of the main features of C # 3 is here with:
- A brief description of the function, usually with an example
- A pair of "Bluff extra power" to launch a conversation phrases to get bonus points from their listeners - if not more evidence
- A couple of "call his bluff," says that sound plausible but are actually incorrect. If you feel another person is perhaps exaggerate their experience, see if the ground traps.
Automatic properties
Automatic properties are an easy way to write the properties you just get and set their values directly from / to a variable of support. For example, this code:
string name;
public string Name
{
get { return name; }
set { name = value; }
}
public string Name { get; set; }
Extra Bluff Power
- The compiler generates the backing variable always contains angle brackets (<>) for the variable can not legitimately be referred to in the C # code, and never be faced with a handwritten variable.
- If you use automatic properties in a structure is necessary to include an explicit call to the constructor without parameters for each additional constructor to write.
Call their bluff
- Automatic Properties is officially called "auto-properties" in the specification. (Fact: They are called out automatically Properties.)
- Automatic properties are indistinguishable from the properties typically generated manually. (Fact: The compiler adds an attribute CompilerGenerated both the getter and setter.)
Object Initializers allow you to configure the properties of a very simple object at the time of construction. Collection initializers are similar, allowing you to complete a collection. Examples:
// Object initializer
ProcessStartInfo psi = new ProcessStartInfo
{
FileName="Notepad.exe",
Arguments="c:\\autoexec.bat",
UseShellExecute=true
};
// Collection initializer for List
List<string> words = new List<string>
{ "the", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog" };
// Collection initializer for Dictionary
Dictionary<string,int> ages = new Dictionary<string,int>
{
{ "Jon", 31 },
{ "Holly", 32 },
{ "Tom", 4 }
};
0 comments:
Post a Comment