Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0097 Field initialization and default value

For class level fields we don't need to set the initial value. C# sets the initial value if the fields aren't initialized. using System; class Rectangle { public int Width; public int Height; } class Program { static void Main(string[] args) { Rectangle r = new Rectangle(); Console.WriteLine(r.Width); } } The output: 0