Use method to init struct member variables : Constructor « struct « C# / CSharp Tutorial






using System;


public struct Simple {

  public  int i;
  private string s;
  

  public void init( ) {
    i = 10;
    s = "Hello";
  }
  
}



public class MainClass {

  public static void Main( ) {

    Simple simple = new Simple();
  
    simple.init( );
    
  }
}








6.3.Constructor
6.3.1.Use method to init struct member variables
6.3.2.Struct constructor with parameters
6.3.3.Structs with constructors
6.3.4.Fraction struct