.NET Framework Bookmark and Share   
 index > Common Language Runtime > Reflection Question
 

Reflection Question

I want to know the principle of the Reflection, which book will teach it?
And if i use (C#)
Type type = OneClass.GetType();
string className = type.Name

to get the ClassName
will it const a lot of cpu time?

is it just like
public class OneClass
{
public string ClassName = "OneClass";
}

string className = OneClass.ClassName ??

Thanks.
otm2000_zhang
There are a lot of articles on internet to learn reflection. Try codeproject and msdn . And using Reflection does not cost a lot of CPU time. It costs a bit. All the type details are loaded when the assembly is loaded in the memory. So, when you use reflection for the types loaded in memory, it costs less.

Your way of using a static string variable is not so efficient, and lacks version, assembly and culture info. And since it is hard coded, it can lead to bugs when the class name changes but the value in variable is not changed.

Hope you get it.
decyclone
There are a lot of articles on internet to learn reflection. Try codeproject and msdn . And using Reflection does not cost a lot of CPU time. It costs a bit. All the type details are loaded when the assembly is loaded in the memory. So, when you use reflection for the types loaded in memory, it costs less.

Your way of using a static string variable is not so efficient, and lacks version, assembly and culture info. And since it is hard coded, it can lead to bugs when the class name changes but the value in variable is not changed.

Hope you get it.
decyclone

You can use google to search for other answers

Custom Search

More Threads

• CLR profiler
• .NET 2.0 Interop: What does MarshalAs want from me?
• Initialize and script ActiveX
• P/invoke marshalling questions
• C++/CLI ok when doubleclick, crashes in mscrowks.dll from process.start
• Creating an Forms Control but getting error "ActiveX control <GUID> cannot be instantiated because the current thread is not in a single-threaded apartment."
• System.Web.Security.ActiveDirectoryMembershipProvide question
• Inherited controls not getting displayed in design view
• unmanaged non-COM based MFC C++ based DLLs in C# code
• GC