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


Please Help Members By Posting Answers For Below Questions

Why do I get a syntax error when trying to declare a variable called checked?

544


what are the differences between a class and structure

538


What does dbml mean in texting?

510


What is private protected in c#?

494


Is null == null c#?

470






What is the use of table aliases?

486


What is type safe in c#?

485


What is difference between private and protected?

495


Define thread? Explain about multithreading?

564


What is difference between singleton and static class in c#?

472


Is Multiple-inheritance supported by c#?

579


What is yield break in c#?

501


Can abstract class be sealed in c#?

464


Why do we need constructor?

484


Can we have multiple threads in one app domain?

513