Page view counter

Definitions

 

 

 

 Definitions Page 

 

 

 

 

 

In many of my blog posts, I refer to fundamentals in C# and Silverlight that may not be familiar to every reader. This page will provide definitions, short explanation and/or pointers to where you can learn more about these constructs.

NB: You will find many references to my own books; not because they are the only -- or even the best -- resource, but they are the ones I know best. If you wish to send me verified references to other sources, please include the source, the page, an image of the part of the page you are referring to, and I’ll update these references.

All books mentioned are shown at the bottom of the page.

Note also that just about everything here can also be found in the C# help files and/or MSDN on line.

 

Definitions

Automatic Properties  Automatic properties relieve you of the need to create redundant and superfluous code. When you write

public int Age { get; set; }
it is treated by the compiler exactly as if you’d written
 
private int age;
public int Age
{
   get { return age; }
   set { age = value; }
}

Note that you must provide both a getter and a setter, but this constraint is easily overcome by using the keyword private with either.  More in Learning C# page 173

---
Implicit Types (var) :C# 3 introduces the idea of Implicitly typed variables, using the keyword var. Note that these are not loosly typed, they are strongly typed variables but the type is determined by the compiler by analyzing the type of the object assigned to the variable. Thus if you have a method

public List<Geeks> GetGeeks();

and you write

var x = GetGeeks();

the type of x is List<Geeks> just exactly as if you had written

List<Geeks> x = GetGeeks();

More on this in Learning C# page 55 and page 147.

---

Object Initialization: Beginning with C# 3, you can initialize instances of a class at the time you create them, rather than passing parameters to a constructor. Thus, where you might have written:

class Person
{
   public string Name { get; set; }
   public int Age { get; set; }
   Person (string name, int age)
   { 
       this.Name = name;
       this.Age = age;
   }
}

Person p = new Person("jesse");

you can now write

class Person
{
   public string Name { get; set; }
}

Person p = new Person { Name = "jesse", Age=21; } 

More on this in Learning C# page 146.

  

  

  

  

---  

Book References

Published Thursday, August 13, 2009 10:36 AM by jesseliberty
Filed under:

Comments

No Comments