Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Access method name in the method itself

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mukesh - 13 Nov 2006 11:52 GMT
Hi,

Could I write a code that will get the method name within which the
code is written.
like I want

void showMethodName(){
string method;
method=Need a method here to get the method name which contains this
code.  In this case it is "showMethodName"
}

Thanks
Chakravarti Mukesh
Ciaran O''Donnell - 13 Nov 2006 12:38 GMT
methodname = new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name;

Ciaran O'Donnell

> Hi,
>
[quoted text clipped - 10 lines]
> Thanks
> Chakravarti Mukesh
Jon Skeet [C# MVP] - 13 Nov 2006 19:20 GMT
> Could I write a code that will get the method name within which the
> code is written.
[quoted text clipped - 5 lines]
> code.  In this case it is "showMethodName"
> }

Ciaran showed you a way, but it should be noted that this is quite
expensive, and should almost always be avoided.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.