Object initialization
In this chapter you will learn:
Shortcut for object initialization
The accessible fields or properties can be called in a single statement to do the initialization.
using System;/*j a v a 2s . c o m*/
class Rectangle{
public int Width;
public int Height;
}
class Program
{
static void Main(string[] args)
{
Rectangle r = new Rectangle { Width = 5, Height = 6 };
Console.WriteLine(r.Width);
}
}
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Class