Assign value to class : Class Definition : Class Interface C# Source Code


Custom Search

C# Source Code » Class Interface » Class Definition »

 

Assign value to class









    

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/


// This program will not compile. 
 
class X { 
  int a; 
 
  public X(int i) { a = i; } 
} 
 
class Y { 
  int a; 
 
  public Y(int i) { a = i; } 
} 
 
public class IncompatibleRef { 
  public static void Main() { 
    X x = new X(10); 
    X x2;  
    Y y = new Y(5); 
 
    x2 = x; // OK, both of same type 
 
    x2 = y; // Error, not of same type 
  } 
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Class Interface
» Class Definition