How to create an object and use it into other methods of a class in C# -


i'm trying write class needs use object in other method of class, consider pseudo code :

class socket {  private (something used other methods) interface_like_method { //initializing socket class //to used other methods }  public filetrasfer (ref socket client) { // here, can use initialized obj of interface_like_method  // client.sendfile("a path") ;  } } 

how such functionality implemented?

declare variable 'instance variable' (also known 'member variable'). means variable can used anywhere in class. if variable declared inside method, method has access it.

class 1 { //code }  class 2 {  1 one; //instance variable accessible in entire class, not initialized  1 oneinitialized = new one(); //this 1 initialized  two() { //this constructor   1 = new one(); //initializes object 'one' declared above  }  somemethod() {   1 secondone = new one(); //can used inside method  }  //use object 'one' anywhere; } 

Popular posts from this blog