Home
 
     
Programming
1 post(s)

Extension methods : how to add more Extra methods to type String, Int or ... very easily ?

You can actually "add" methods to existing types very easily even without creating a new derived type. This is exreamly cool fast and time to times it comes in handy. I am going to tell you very simply othrwise you can read the official supper correct version on MSDN. 

assume we have a string like this:

string myString = "Hello! ";

Then normally we can have some string type methods like 

myString.Substring(startIndex);
myString.IndexOf(value,value);.  

But how about if we want to have our own methods in this type for example
 myString.AddCool();
that for example returns 
"Hello! Cool"  

Privacy Statement Terms Of Use Copyright 2011 by Rooznamechi