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 a namespace server?
What is the difference between public, static, and void?
Define parsing? Explain how to parse a datetime string?
Is static thread safe?
What is the benefit of dependency injection c#?
If you define a user defined data type by using the struct keyword, is it a value type or reference type?
What is the difference between ienumerable and enumerable?
What is the difference between abstract class and interface in c#?
What are some of the commonly used commands in sqlcommand?
What is the difference between list and arraylist c#?
What are destructors in C#?
What is signature c#?
What is data type in c# with example?
How do I register my code for use by classic com clients?
What is a private method in c#?