Disabilita Adblock

Adblock sta bloccando alcuni contenuti sul sito

ADBlock errore

Domanda

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?

Nessuna soluzione corretta

Altri suggerimenti

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 } }

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow