Is there any way to access private memebers of an object
from another object?
Answer Posted / porchelvi.a
We can achieve this by using Reflection.
By using Reflection we can access some information about
object at runtime.even we can invoke private method of an
object by using Reflection.
Example :
Class Student
{
private int RollNo;
public string Name;
}
class MainClass
{
Type type=typeof(Student); //to get type information
MemberInfo[] mem=type.getMembers();
foreach(Memberinfo m in mem)
//we can get every member here
}
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
What is xslt in c#?
what is a destructor?
What are extension methods and where can we use them?
Explain how to add controls dynamically to the form using c#.net.
Distinguish between system.string and system.text.stringbuilder classes?
Why reflection is used in c#?
Can You Prevent Your Class From Being Inherited By Another Class?
How do you mark a method obsolete?
Why do we use yield in c#?
What is garbage collection? How to force garbage collector to run?
What is an assembly qualified name
what are implementation inheritance and interface inheritance?
Which class does the remote object has to inherit?
What is readline c#?
What is string pool in c#?