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

What is for loop in c#?

711


What is lazy class in c#?

664


Why data types are important?

745


State two different types of access modifiers.

791


Can firstordefault return null?

735


What is parallel programming in c#?

712


What is a method c#?

699


Explain streamreader/streamwriter class?

755


Is versioning applicable to private assemblies?

783


Which of the following API is used to hide a window?

801


What is final keyword in c#?

734


Why is c# better than java?

710


Does c# support properties of array types?

744


what are pointer types in c#

777


What is the difference between dataset and datatable in c#?

781