Click here to Skip to main content
15,890,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For example:
C#
Convert.ToInt32()


this method converts the value to int, is it possible to see the source code of this method which is written by microsoft.

Thanks to all for your response, I need to add more details to my question.

I can get the souce code of any method on microsoft site.
But how i can see the methods which are internally implemented

for ex:
How i can find the source code of methods which i don't know to which class they belong
i.e
C#
int i='x';

here char 'x' is implicitly converted to i. The i gets the ASCII value of x.
Where i can find its implementation

Hope you understand the question.
Posted
Updated 19-Aug-15 4:48am
v3
Comments
Sergey Alexandrovich Kryukov 19-Aug-15 10:18am    
First of all, I would avoid using this very method. Use int.Parse, int.TryParse instead.
—SA
CHill60 19-Aug-15 10:19am    
Virtual 5!
Sergey Alexandrovich Kryukov 19-Aug-15 10:24am    
Thank you, but I also answered the question ;-)
—SA
Mario Z 19-Aug-15 10:21am    
I agree, but nevertheless that method will basically just call the Int32.Parse itself with a current culture info.
Sergey Alexandrovich Kryukov 19-Aug-15 10:23am    
Sure.
—SA

Yes it is possible, you can find the method here[^].
Also you can use the following VS extension to do this inside a VS as well:
Ref12[^]
 
Share this answer
 
Comments
CHill60 19-Aug-15 10:19am    
Beat me to it! 5'd
Sergey Alexandrovich Kryukov 19-Aug-15 10:23am    
5ed.
—SA
Member 9129971 19-Aug-15 10:32am    
Ok but how can i find the source code of methods which i dont know to which class they belong. For example
int i='x';
here character is automatically converted to int, no error generated , ASII value goes to i.
So where i can find the implementation for this, in which Class,Assembly?
Mario Z 19-Aug-15 10:58am    
First regarding any method, what you can do is add that VS extension that I linked above and then right click on the desired method and click "Go To Definition".
Also another thing that you can actually do is step through .NET's methods while you are debugging, see here how to enable this.

But regarding your specific example ("int i='x';"), this is not a method but rather an implicit conversion operator, you would have to view this with roslyn.
Member 9129971 21-Aug-15 6:26am    
I guess you mean that after installing roslyn and enabling .net source debug .I would be able to debug the implementation of this implicit conversion operator by adding breakpoint over it.I have followed these two links and now added breakpoint to see if it goes to implementation but its not working ,i can't figure out where i am going wrong.
Yes, you can get access to the source code of .NET libraries. Please see: http://referencesource.microsoft.com[^].

See also my comment to the question. Instead of Convert, use parsing methods like int.Parse and int.TryParse. Convert class is useful in number of other cases.

—SA
 
Share this answer
 

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