Interesting C# 2
public class Address
{
public string Name;
public string City;
}
intead of
public class Address
{
private string _name;
public string Name
{
get{return _name;}
set{ _name = value;}
}
private string _city;
public string City
{
get { return _city; }
set { _city = value; }
}
}
Here is one benifit...
Address aa = new Address();
aa.Name = "hero";
aa.City = "bombay";
textBox1.DataBindings.Add("Text", aa, "City");
{
get { lock( this )
{ return _name; }
}
set { lock( this )
{ _name = value; }
}
}
Multithreading for properties is easy to implement
public class Customer
{
private string _name;
public virtual string Name
{
get
{
return _name;
}
protected set
{
_name = value;
}
}
}
public const int A = 20;
// Runtime constant: not very fast but flexible to change
public static readonly int A = 24;
{
private string _name;
public string Name
{
get{return _name;}
set{ _name = value;}
}
private string _city;
public string City
{
get { return _city; }
set { _city = value; }
}
public static implicit operator MyType(Address s )
{
return new MyType(s.City ,s.Name ) ;
}
}
public class MyType
{
public MyType(string h, string j)
{
}
}
now you can cast directly
Address aa = new Address();
aa.Name = ""; aa.City = "bombay";
MyType m = aa;