Click here to Skip to main content
15,905,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all,

I would like to have method like .ToString()

say int i=100;

if i.ToCustomInt();
then out put of "i" should show 105(i+some constant value(5) then out put would be 105);

i tried to have sealed class and static method "ToCustomInt()".
wondering how to get that "i" value inside of the static method..

is there any suggestion please.
Posted
Comments
walterhevedeich 23-Aug-11 1:20am    
Show us what you have tried

This can be done by "Extension Methods". check the following KB article:

http://msdn.microsoft.com/en-us/library/bb383977.aspx[^]
 
Share this answer
 
Comments
Simon Bang Terkildsen 23-Aug-11 1:40am    
+5
Sathish Kumar. K 23-Aug-11 2:04am    
Hi Simon Bang Terkildsen ,
Thank you so much.
I gree with Om Prakash Pant, this is a job for an extension method.

Here is an example
C#
public static class IntExtensions
{
    public static int ToCustomInt(this Int32 i)
    {
        return i + 5;
    }
}
 
Share this answer
 
Comments
Sathish Kumar. K 23-Aug-11 2:03am    
Hi Om Prakash Pant,
Thank you so much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900