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
}
}
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Dec 30, 2011, 1:16 AM
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
AartiPosted Dec 30, 2011, 1:59 AM
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.