HiCan any one tell how can i acces outerClass member in innerClass................? public class OuterClass
{
public string name="Hidaya Trust";
public int id=45;
class InnerClass {
//I want to access here outerClass memeber
}
}
Member Accessing Problem in Nested classes
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 29, 2011, 8:16 PM EST
Try this...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class OuterClass
{
public string name = "Hidaya Trust";
public int id = 45;
class InnerClass
{
public static void Main(string[] arg)
{
OuterClass oc = new OuterClass();
System.Console.WriteLine(oc.name);
System.Console.WriteLine(oc.id);
System.Console.ReadLine();
}
}
}
}
Thanks
If this post helps you mark it as answer
AartiRank #2,383 · 594 reputationPosted Dec 29, 2011, 8:59 PM EST
you can access OuterClass Member in Inner Class in two ways.
1. Declare outerclass member as static
2. call non static member of outer class in inner class by declaring public static member function in Inner class and then access member with in static function.