public static void MainType(string[] args) { // Struct variables are manged by value // eg. Alien coordinates, single value not shared // value types are Enumerated types and structures StructStore xs, ys; ys = new StructStore(); ys.Data = 99; xs = ys; xs.Data = 100; Console.WriteLine("xStruct: {0}", xs.Data); Console.WriteLine("yStruct: {0}", ys.Data); // Class variables are managed by reference // eg. Alien sound effects, shared // Reference types are classes ClassStore xc, yc; yc = new ClassStore(); yc.Data = 99; xc = yc; xc.Data = 100; Console.WriteLine("xClass: {0}", xc.Data); Console.WriteLine("yClass: {0}", yc.Data); }
static void Main(string[] args) { //CTO: value types are enumerated types and structures, reference types are classes. //CTO: Variaveis do tipo struct são manejadas por valor StructStore xs, ys; ys = new StructStore(); ys.Data = 99; xs = ys; xs.Data = 100; Console.WriteLine("xStruct: {0}", xs.Data); Console.WriteLine("yStruct: {0}", ys.Data); //CTO: Variaveis do tipo class são manejadas por referencia ClassStore xc, yc; yc = new ClassStore(); yc.Data = 99; xc = yc; xc.Data = 100; Console.WriteLine("xClass: {0}", xc.Data); Console.WriteLine("yClass: {0}", yc.Data); Console.ReadKey(); }
public static void RunTestValueAndReferenceTypes() { //Structure variables are managed by value //Changes to variable xStructs does not affect value of yStruct StructStore xs, ys; ys = new StructStore(); ys.Data = 99; xs = ys; xs.Data = 100; Console.WriteLine("xStruct: {0}", xs.Data); Console.WriteLine("yStruct: {0}", ys.Data); //class variables are managed by reference //xClass and yClass referr to the same object ClassStore xc, yc; yc = new ClassStore(); yc.Data = 99; Console.WriteLine("\nyClass first: {0}", yc.Data); xc = yc; Console.WriteLine("xClasst first: {0}", xc.Data); xc.Data = 100; Console.WriteLine("\nClass and yClass referr to the same object {0} as x and {1} as y", xc.Data, yc.Data); Console.WriteLine("\nxClass after : {0}", xc.Data); Console.WriteLine("yClass after: {0}", yc.Data); }
public void StartCommand() { StructStore xs, ys; ys = new StructStore(); ys.Data = 99; xs = ys; xs.Data = 100; Console.WriteLine("xStruct: {0}", xs.Data); Console.WriteLine("yStruct: {0}", ys.Data); ClassStore xc, yc; yc = new ClassStore(); yc.Data = 99; xc = yc; xc.Data = 100; Console.WriteLine("xClass: {0}", xc.Data); Console.WriteLine("yClass: {0}", yc.Data); AlienState alienState = AlienState.Attacking; Console.WriteLine("State of alien {0}", alienState); AlienBit alienBit = AlienBit.Attacking; Console.WriteLine("State of alien bit {0}", alienBit); Console.ReadKey(); }
protected void FillClassIdCombo(object sender, DirectEventArgs e) { if (!string.IsNullOrEmpty(moduleId.SelectedItem.Value.ToString())) { AccessControlListRequest req = new AccessControlListRequest(); req.GroupId = "0"; req.ModuleId = moduleId.SelectedItem.Value.ToString(); ListResponse <ModuleClass> resp = _systemService.ChildGetAll <ModuleClass>(req); if (!resp.Success) { Common.errorMessage(resp); return; } ClassStore.DataSource = resp.Items; ClassStore.DataBind(); } }
/// <summary> /// ///////////////// /// </summary> // The diff between reference and value types is crucial public void ValueAndReferenceTypes() { StructStore xs, ys; ys = new StructStore(); ys.Data = 99; xs = ys; xs.Data = 100; Console.WriteLine("xStruct: {0}", xs.Data); // 100 Console.WriteLine("yStruct: {0}", ys.Data); // 99 ClassStore xc, yc; yc = new ClassStore(); yc.Data = 99; xc = yc; xc.Data = 100; Console.WriteLine("xClass: {0}", xc.Data); // 100 Console.WriteLine("yClass: {0}", yc.Data); // 100 }
static void Main(string[] args) { StructStore xs, ys; ys = new StructStore(); ys.Data = 99; xs = ys; xs.Data = 100; Console.WriteLine("xStruct:{0}", xs.Data); Console.WriteLine("yStruct:{0}", ys.Data); ClassStore xc, yc; yc = new ClassStore(); yc.Data = 99; xc = yc; xc.Data = 100; Console.WriteLine("xClass:{0}", xc.Data); Console.WriteLine("yClass:{0}", yc.Data); Console.ReadKey(); }
private static void Main(string[] args) { StructStore xs, ys; ys = new StructStore { Data = 99 }; xs = ys; xs.Data = 100; Console.WriteLine("xStruct: {0}", xs.Data); Console.WriteLine("yStruct: {0}", ys.Data); ClassStore xc, yc; yc = new ClassStore { Data = 99 }; xc = yc; xc.Data = 100; Console.WriteLine("xClass: {0}", xc.Data); Console.WriteLine("yClass: {0}", yc.Data); Console.ReadKey(); /* Output: * * xStruct: 100 * yStruct: 99 * * and * * xStruct: 100 * yStruct: 100 * */ }
public static void executeTest() { StrucStore xs, ys; ys = new StrucStore(); ys.Data = 99; xs = ys; xs.Data = 100; Console.WriteLine($"xStrcut {xs.Data}"); Console.WriteLine($"yStrcut {ys.Data}"); ClassStore xc, yc; yc = new ClassStore(); yc.Data = 99; xc = yc; xc.Data = 100; Console.WriteLine($"xClass {xc.Data}"); Console.WriteLine($"yClass {yc.Data}"); Console.ReadKey(); }
//struct will not influence previous value, class will internal void StructVsEnum() { StructStore xs, ys; ys = new StructStore(); ys.Data = 99; xs = ys; xs.Data = 100; Console.WriteLine("xStruct: {0}", xs.Data); Console.WriteLine("yStruct: {0}", ys.Data); ClassStore xc, yc; yc = new ClassStore(); yc.Data = 99; xc = yc; xc.Data = 100; Console.WriteLine("xClass: {0}", xc.Data); Console.WriteLine("yClass: {0}", yc.Data); Console.ReadKey(); }
public static void main() { Console.WriteLine("Value type"); StuctStore xs, ys; ys = new StuctStore(); ys.Data = 99; xs = ys; xs.Data = 100; Console.WriteLine("xStruct: {0}", xs.Data); Console.WriteLine("yStruct: {0}", ys.Data); Console.WriteLine("\nReference type"); ClassStore xc, yc; yc = new ClassStore(); yc.Data = 99; xc = yc; xc.Data = 100; Console.WriteLine("xClass: {0}", xc.Data); Console.WriteLine("yClass: {0}", yc.Data); }
static void Main(string[] args) { StructStore x, y; y = new StructStore(); y.Data = 4; x = y; x.Data = 100; Console.WriteLine("y = {0}", y.Data); Console.WriteLine("x = {0}", x.Data); ClassStore a, b; a = new ClassStore(); a.Data = 3; b = a; a.Data = 12; Console.WriteLine("a = {0}", a.Data); Console.WriteLine("b = {0}", b.Data); Console.ReadKey(); }
private static void ValueAndReferenceTypesExample() { /* Structure variables are managed by value (changes to xStruct do not affect yStruct) */ /* Value types are great for working with objects that you want to think of in terms of * values */ StructStore xs, ys; ys = new StructStore(); ys.Data = 99; xs = ys; xs.Data = 100; Console.WriteLine("xStruct: {0}", xs.Data); Console.WriteLine("yStruct: {0}", ys.Data); /* Outputs: * xStruct: 100 * yStruct: 99 */ /* Class variables are managed by reference (xClass and yClass both refer to the same object, * so changes via the xClass reference will affect the value referred to by yClass) */ /* Reference types are great for working with objects that you want to manage by reference */ ClassStore xc, yc; yc = new ClassStore(); yc.Data = 99; xc = yc; xc.Data = 100; Console.WriteLine("xClass: {0}", xc.Data); Console.WriteLine("yClass: {0}", yc.Data); /* Outputs: * xClass: 100 * yClass: 100 */ }