IntroductionThis article is about the use of reflection package in Csharp. Through Reflection we can get Information about the class. It is very useful in designing COM ..we don't have to remember the method name and all other related information regarding class ,we can get it through reflection package.About ProgramThis program contain one class Reflect and other one is TCPReflection. Through TCPReflection we are getting information about Reflect class in TCPReflection. In TCPReflection we are getting information member information,Field information and method information of Reflect class. I am giving you this program as simple as possible to understand you can do this with available classes of Csharp also like TCPClient etc.Compile : csc TCPReflection.csexecute : TCPReflectionSource Codeusing System.Reflection;using System;class Reflect{public int i=20;public char ch='a';public float f1=10;public void GetFloat(){Console.WriteLine(f1);}public void GetInt(){Console.WriteLine(i);}public void GetChar(){Console.WriteLine(ch);}}class TCPReflection{public void GetInfo(){ Reflect sender = new Reflect();Type t = sender.GetType();MemberInfo [] members = t.GetMembers();MethodInfo [] method = t.GetMethods();FieldInfo [] f1=t.GetFields();Console.WriteLine("Name of Object "+t.FullName);Console.WriteLine("no of memeber:"+members.Length);Console.WriteLine("no of fileds:"+f1.Length);Console.WriteLine("Member of class Reflect is as follows:" );foreach(MemberInfo m in members){Console.WriteLine(m.Name);}Console.WriteLine("Methods of class Reflect is as follows:" );foreach(MethodInfo m in method){Console.WriteLine(m.Name);}Console.WriteLine("Fields of class Reflect is as follows:" );foreach(FieldInfo f in f1){Console.WriteLine(f.Name);}}public static void Main(){TCPReflection p1 = new TCPReflection();p1.GetInfo();}}
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: