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
How is lazy loading achieved?
How do I declare inout arguments in c#?
Why do we use threads in c#?
Can you store different types in an array in c#?
What is COM Interoperability?
What does char mean in c#?
Explain dataset.acceptchanges method in .net?
What is the use of 'as' Keyword in C# ?
What is _viewstart cshtml?
Can a abstract class have a constructor?
What is the difference between method overriding and method overloading?
how background thread access to ui control?
Which is the best language for desktop application?
Explain the difference between access specifier and access modifier in c#?
Why do we use namespace in c#?