Presently in c# 3.5 we all are just using the function overloading in order to provide the default or optional parameter functionality.e.g
public class oldclassBut now in c# 4 what we do is:-
{
public string A{ get; set; }
public string B{ get; set; }
public string C{ get; set; }
public oldclass(string a)
{
A= a;
B= "B";
C= string.Empty;
}
public oldclass(string a, string b)
{
A= a;
B= b;
C= string.Empty;
}
public oldclass(string a, string b, string c)
{
A= a;
B= b;
C= c;
}
}
public class newclassif we initialize constructor using-> new newclass("A");
{
public string A{ get; set; }
public string B{ get; set; }
public string C{ get; set; }
public newclass(string a, string b="B", string c=string.Empty)
{
A= a;
B= b;
C= c;
}
}
then values for A="A",B="B"and C="".
So,Its quite cool to include this feature in c# 4 so that now,we don't have to use function overloading for getting functionality of optional parameters.
No comments:
Post a Comment