clearcase/" target="_blank" >cccccc">000: // Structs\struct1.cs 001: using System; 002: struct SimpleStruct 003: { 004: private int xval; 005: public int X 006: { 007: get { 008: return xval; 009: } 010: set { 011: if (value < 100) 012: xval = value; 013: } 014: } 015: public void DisplayX() 016: { 017: Console.WriteLine("The stored value is: {0}", xval); 018: } 019: } 020: 021: class TestClass 022: { 023: public static void Main() 024: { 025: SimpleStruct ss = new SimpleStruct(); 026: ss.X = 5; 027: ss.DisplayX(); 028: } 029: } |
000: // Structs\struct2.cs 001: using System; 002: 003: class TheClass 004: { 005: public int x; 006: } 007: 008: struct TheStruct 009: { 010: public int x; 011: } 012: 013: class TestClass 014: { 015: public static void structtaker(TheStruct s) 016: { 017: s.x = 5; 018: } 019: public static void classtaker(TheClass c) 020: { 021: c.x = 5; 022: } 023: public static void Main() 024: { 025: TheStruct a = new TheStruct(); 026: TheClass b = new TheClass(); 027: a.x = 1; 028: b.x = 1; 029: structtaker(a); 030: classtaker(b); 031: Console.WriteLine("a.x = {0}", a.x); 032: Console.WriteLine("b.x = {0}", b.x); 033: } 034: } |
interface IImage { void Paint(); } struct Picture : IImage { public void Paint() { // painting code goes here } private int x, y, z; // other struct members } |