سؤال

I'm currently working on a C# project, i'm new to C# so i'm not that familiar with classes and all. anyway here is my sample program structure:

 class foo 
 { 
     public foo(String txt) : base(new MyInnerClass()) { }
     private class MyInnerClass
     { }
 }

the problem is that i want to access my String txt to MyInnerClass, but i don't know how. The value of String txt comes from other class that will access this class foo. Any idea how?

لا يوجد حل صحيح

نصائح أخرى

You can either create a settable property on MyInnerClass, or give it a constructor that takes a string, as you've done with foo.

class foo 
{ 
   public foo(String txt) : base(new MyInnerClass(txt)) { }

   private class MyInnerClass
   { 
       private string text;
       public MyInnerClass(string txt)
       { 
           this.text = txt;
       }
   }
}

just pass it into constructor of base.

class foo { 
public foo(String txt):
           base(new MyInnerClass(txt)){
             } 
   private class MyInnerClass { //some code lines } }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top