diff --git a/03 - Classes 101/A Simple Class/Build1.bat b/03 - Classes 101/A Simple Class/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/03 - Classes 101/A Simple Class/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/03 - Classes 101/A Simple Class/Build2.bat b/03 - Classes 101/A Simple Class/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/03 - Classes 101/A Simple Class/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/03 - Classes 101/A Simple Class/File_1.cs b/03 - Classes 101/A Simple Class/File_1.cs new file mode 100644 index 0000000..e292f94 --- /dev/null +++ b/03 - Classes 101/A Simple Class/File_1.cs @@ -0,0 +1,13 @@ +// 05 - Classes 101\A Simple Class +// copyright 2000 Eric Gunnerson +class VerySimple +{ + int simpleValue = 0; +} +class Test +{ + public static void Main() + { + VerySimple vs = new VerySimple(); + } +} \ No newline at end of file diff --git a/03 - Classes 101/A Simple Class/File_2.cs b/03 - Classes 101/A Simple Class/File_2.cs new file mode 100644 index 0000000..ed4ba6f --- /dev/null +++ b/03 - Classes 101/A Simple Class/File_2.cs @@ -0,0 +1,26 @@ +// 05 - Classes 101\A Simple Class +// copyright 2000 Eric Gunnerson +using System; +class Point +{ + // constructor + public Point(int x, int y) + { + this.x = x; + this.y = y; + } + + // member fields + public int x; + public int y; +} + +class Test +{ + public static void Main() + { + Point myPoint = new Point(10, 15); + Console.WriteLine("myPoint.x {0}", myPoint.x); + Console.WriteLine("myPoint.y {0}", myPoint.y); + } +} \ No newline at end of file diff --git a/03 - Classes 101/Member Functions/Build1.bat b/03 - Classes 101/Member Functions/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/03 - Classes 101/Member Functions/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/03 - Classes 101/Member Functions/File_1.cs b/03 - Classes 101/Member Functions/File_1.cs new file mode 100644 index 0000000..d28141b --- /dev/null +++ b/03 - Classes 101/Member Functions/File_1.cs @@ -0,0 +1,29 @@ +// 05 - Classes 101\Member Functions +// copyright 2000 Eric Gunnerson +using System; +class Point +{ + public Point(int x, int y) + { + this.x = x; + this.y = y; + } + + // accessor functions +public int GetX() {return(x);} +public int GetY() {return(y);} + + // variables now private + int x; + int y; +} + +class Test +{ + public static void Main() + { + Point myPoint = new Point(10, 15); + Console.WriteLine("myPoint.X {0}", myPoint.GetX()); + Console.WriteLine("myPoint.Y {0}", myPoint.GetY()); + } +} \ No newline at end of file diff --git a/03 - Classes 101/Overloading/Build1.bat b/03 - Classes 101/Overloading/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/03 - Classes 101/Overloading/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/03 - Classes 101/Overloading/File_1.cs b/03 - Classes 101/Overloading/File_1.cs new file mode 100644 index 0000000..f13159d --- /dev/null +++ b/03 - Classes 101/Overloading/File_1.cs @@ -0,0 +1,29 @@ +// 05 - Classes 101\Overloading +// copyright 2000 Eric Gunnerson +class Point +{ + // create a new point from x and y values + public Point(int x, int y) + { + this.x = x; + this.y = y; + } + // create a point from an existing point + public Point(Point p) + { + this.x = p.x; + this.y = p.y; + } + + int x; + int y; +} + +class Test +{ + public static void Main() + { + Point myPoint = new Point(10, 15); + Point mySecondPoint = new Point(myPoint); + } +} \ No newline at end of file diff --git a/03 - Classes 101/Ref and Out Parameters/Build1.bat b/03 - Classes 101/Ref and Out Parameters/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/03 - Classes 101/Ref and Out Parameters/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/03 - Classes 101/Ref and Out Parameters/Build2.bat b/03 - Classes 101/Ref and Out Parameters/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/03 - Classes 101/Ref and Out Parameters/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/03 - Classes 101/Ref and Out Parameters/Build3.bat b/03 - Classes 101/Ref and Out Parameters/Build3.bat new file mode 100644 index 0000000..b764232 --- /dev/null +++ b/03 - Classes 101/Ref and Out Parameters/Build3.bat @@ -0,0 +1 @@ +csc File_3.cs diff --git a/03 - Classes 101/Ref and Out Parameters/File_1.cs b/03 - Classes 101/Ref and Out Parameters/File_1.cs new file mode 100644 index 0000000..d36b7ec --- /dev/null +++ b/03 - Classes 101/Ref and Out Parameters/File_1.cs @@ -0,0 +1,35 @@ +// 05 - Classes 101\Ref and Out Parameters +// copyright 2000 Eric Gunnerson +// error +using System; +class Point +{ + public Point(int x, int y) + { + this.x = x; + this.y = y; + } + // get both values in one function call + public void GetPoint(ref int x, ref int y) + { + x = this.x; + y = this.y; + } + + int x; + int y; +} + +class Test +{ + public static void Main() + { + Point myPoint = new Point(10, 15); + int x; + int y; + + // illegal + myPoint.GetPoint(ref x, ref y); + Console.WriteLine("myPoint({0}, {1})", x, y); + } +} \ No newline at end of file diff --git a/03 - Classes 101/Ref and Out Parameters/File_2.cs b/03 - Classes 101/Ref and Out Parameters/File_2.cs new file mode 100644 index 0000000..0629326 --- /dev/null +++ b/03 - Classes 101/Ref and Out Parameters/File_2.cs @@ -0,0 +1,33 @@ +// 05 - Classes 101\Ref and Out Parameters +// copyright 2000 Eric Gunnerson +using System; +class Point +{ + public Point(int x, int y) + { + this.x = x; + this.y = y; + } + + public void GetPoint(ref int x, ref int y) + { + x = this.x; + y = this.y; + } + + int x; + int y; +} + +class Test +{ + public static void Main() + { + Point myPoint = new Point(10, 15); + int x = 0; + int y = 0; + + myPoint.GetPoint(ref x, ref y); + Console.WriteLine("myPoint({0}, {1})", x, y); + } +} \ No newline at end of file diff --git a/03 - Classes 101/Ref and Out Parameters/File_3.cs b/03 - Classes 101/Ref and Out Parameters/File_3.cs new file mode 100644 index 0000000..7e8a57f --- /dev/null +++ b/03 - Classes 101/Ref and Out Parameters/File_3.cs @@ -0,0 +1,33 @@ +// 05 - Classes 101\Ref and Out Parameters +// copyright 2000 Eric Gunnerson +using System; +class Point +{ + public Point(int x, int y) + { + this.x = x; + this.y = y; + } + + public void GetPoint(out int x, out int y) + { + x = this.x; + y = this.y; + } + + int x; + int y; +} + +class Test +{ + public static void Main() + { + Point myPoint = new Point(10, 15); + int x; + int y; + + myPoint.GetPoint(out x, out y); + Console.WriteLine("myPoint({0}, {1})", x, y); + } +} \ No newline at end of file diff --git a/04 - Base Classes and Inheritance/Abstract Classes/Build1.bat b/04 - Base Classes and Inheritance/Abstract Classes/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/04 - Base Classes and Inheritance/Abstract Classes/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/04 - Base Classes and Inheritance/Abstract Classes/Build2.bat b/04 - Base Classes and Inheritance/Abstract Classes/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/04 - Base Classes and Inheritance/Abstract Classes/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/04 - Base Classes and Inheritance/Abstract Classes/File_1.cs b/04 - Base Classes and Inheritance/Abstract Classes/File_1.cs new file mode 100644 index 0000000..c2ce0fc --- /dev/null +++ b/04 - Base Classes and Inheritance/Abstract Classes/File_1.cs @@ -0,0 +1,49 @@ +// 06 - Base Classes and Inheritance\Abstract Classes +// copyright 2000 Eric Gunnerson +using System; +class Engineer +{ + public Engineer(string name, float billingRate) + { + this.name = name; + this.billingRate = billingRate; + } + + virtual public float CalculateCharge(float hours) + { + return(hours * billingRate); + } + + virtual public string TypeName() + { + return("Engineer"); + } + + private string name; + protected float billingRate; +} +class ChemicalEngineer: Engineer +{ + public ChemicalEngineer(string name, float billingRate) : + base(name, billingRate) + { + } + + // overrides mistakenly omitted +} +class Test +{ + public static void Main() + { + Engineer[] earray = new Engineer[2]; + earray[0] = new Engineer("George", 15.50F); + earray[1] = new ChemicalEngineer("Dr. Curie", 45.50F); + + Console.WriteLine("{0} charge = {1}", + earray[0].TypeName(), + earray[0].CalculateCharge(2F)); + Console.WriteLine("{0} charge = {1}", + earray[1].TypeName(), + earray[1].CalculateCharge(0.75F)); + } +} \ No newline at end of file diff --git a/04 - Base Classes and Inheritance/Abstract Classes/File_2.cs b/04 - Base Classes and Inheritance/Abstract Classes/File_2.cs new file mode 100644 index 0000000..382ffa6 --- /dev/null +++ b/04 - Base Classes and Inheritance/Abstract Classes/File_2.cs @@ -0,0 +1,71 @@ +// 06 - Base Classes and Inheritance\Abstract Classes +// copyright 2000 Eric Gunnerson +using System; +abstract class Engineer +{ + public Engineer(string name, float billingRate) + { + this.name = name; + this.billingRate = billingRate; + } + + virtual public float CalculateCharge(float hours) + { + return(hours * billingRate); + } + + abstract public string TypeName(); + + private string name; + protected float billingRate; +} + +class CivilEngineer: Engineer +{ + public CivilEngineer(string name, float billingRate) : + base(name, billingRate) + { + } + + override public float CalculateCharge(float hours) + { + if (hours < 1.0F) + hours = 1.0F; // minimum charge. + return(hours * billingRate); + } + + // This override is required, or an error is generated. + override public string TypeName() + { + return("Civil Engineer"); + } +} + +class ChemicalEngineer: Engineer +{ + public ChemicalEngineer(string name, float billingRate) : + base(name, billingRate) + { + } + + override public string TypeName() + { + return("Chemical Engineer"); + } +} +class Test +{ + public static void Main() + { + Engineer[] earray = new Engineer[2]; + earray[0] = new CivilEngineer("Sir John", 40.0F); + earray[1] = new ChemicalEngineer("Dr. Curie", 45.0F); + + Console.WriteLine("{0} charge = {1}", + earray[0].TypeName(), + earray[0].CalculateCharge(2F)); + Console.WriteLine("{0} charge = {1}", + earray[1].TypeName(), + earray[1].CalculateCharge(0.75F)); + } +} \ No newline at end of file diff --git a/04 - Base Classes and Inheritance/Arrays of Engineers/Build1.bat b/04 - Base Classes and Inheritance/Arrays of Engineers/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/04 - Base Classes and Inheritance/Arrays of Engineers/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/04 - Base Classes and Inheritance/Arrays of Engineers/Build3.bat b/04 - Base Classes and Inheritance/Arrays of Engineers/Build3.bat new file mode 100644 index 0000000..b764232 --- /dev/null +++ b/04 - Base Classes and Inheritance/Arrays of Engineers/Build3.bat @@ -0,0 +1 @@ +csc File_3.cs diff --git a/04 - Base Classes and Inheritance/Arrays of Engineers/File_1.cs b/04 - Base Classes and Inheritance/Arrays of Engineers/File_1.cs new file mode 100644 index 0000000..6ea83e7 --- /dev/null +++ b/04 - Base Classes and Inheritance/Arrays of Engineers/File_1.cs @@ -0,0 +1,60 @@ +// 06 - Base Classes and Inheritance\Arrays of Engineers +// copyright 2000 Eric Gunnerson +using System; +class Engineer +{ + public Engineer(string name, float billingRate) + { + this.name = name; + this.billingRate = billingRate; + } + + public float CalculateCharge(float hours) + { + return(hours * billingRate); + } + + public string TypeName() + { + return("Engineer"); + } + + private string name; + protected float billingRate; +} +class CivilEngineer: Engineer +{ + public CivilEngineer(string name, float billingRate) : + base(name, billingRate) + { + } + + public new float CalculateCharge(float hours) + { + if (hours < 1.0F) + hours = 1.0F; // minimum charge. + return(hours * billingRate); + } + + public new string TypeName() + { + return("Civil Engineer"); + } +} +class Test +{ + public static void Main() + { + // create an array of engineers + Engineer[] earray = new Engineer[2]; + earray[0] = new Engineer("George", 15.50F); + earray[1] = new CivilEngineer("Sir John", 40F); + + Console.WriteLine("{0} charge = {1}", + earray[0].TypeName(), + earray[0].CalculateCharge(2F)); + Console.WriteLine("{0} charge = {1}", + earray[1].TypeName(), + earray[1].CalculateCharge(0.75F)); + } +} \ No newline at end of file diff --git a/04 - Base Classes and Inheritance/Arrays of Engineers/File_3.cs b/04 - Base Classes and Inheritance/Arrays of Engineers/File_3.cs new file mode 100644 index 0000000..afacd83 --- /dev/null +++ b/04 - Base Classes and Inheritance/Arrays of Engineers/File_3.cs @@ -0,0 +1,82 @@ +// 06 - Base Classes and Inheritance\Arrays of Engineers +// copyright 2000 Eric Gunnerson +using System; +enum EngineerTypeEnum +{ + Engineer, + CivilEngineer +} +class Engineer +{ + public Engineer(string name, float billingRate) + { + this.name = name; + this.billingRate = billingRate; + type = EngineerTypeEnum.Engineer; + } + + public float CalculateCharge(float hours) + { + if (type == EngineerTypeEnum.CivilEngineer) + { + CivilEngineer c = (CivilEngineer) this; + return(c.CalculateCharge(hours)); + } + else if (type == EngineerTypeEnum.Engineer) + return(hours * billingRate); + return(0F); + } + + public string TypeName() + { + if (type == EngineerTypeEnum.CivilEngineer) + { + CivilEngineer c = (CivilEngineer) this; + return(c.TypeName()); + } + else if (type == EngineerTypeEnum.Engineer) + return("Engineer"); + return("No Type Matched"); + } + + private string name; + protected float billingRate; + protected EngineerTypeEnum type; +} + +class CivilEngineer: Engineer +{ + public CivilEngineer(string name, float billingRate) : + base(name, billingRate) + { + type = EngineerTypeEnum.CivilEngineer; + } + + public new float CalculateCharge(float hours) + { + if (hours < 1.0F) + hours = 1.0F; // minimum charge. + return(hours * billingRate); + } + + public new string TypeName() + { + return("Civil Engineer"); + } +} +class Test +{ + public static void Main() + { + Engineer[] earray = new Engineer[2]; + earray[0] = new Engineer("George", 15.50F); + earray[1] = new CivilEngineer("Sir John", 40F); + + Console.WriteLine("{0} charge = {1}", + earray[0].TypeName(), + earray[0].CalculateCharge(2F)); + Console.WriteLine("{0} charge = {1}", + earray[1].TypeName(), + earray[1].CalculateCharge(0.75F)); + } +} \ No newline at end of file diff --git a/04 - Base Classes and Inheritance/Sealed Classes and Methods/Build1.bat b/04 - Base Classes and Inheritance/Sealed Classes and Methods/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/04 - Base Classes and Inheritance/Sealed Classes and Methods/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/04 - Base Classes and Inheritance/Sealed Classes and Methods/File_1.cs b/04 - Base Classes and Inheritance/Sealed Classes and Methods/File_1.cs new file mode 100644 index 0000000..a75f4ef --- /dev/null +++ b/04 - Base Classes and Inheritance/Sealed Classes and Methods/File_1.cs @@ -0,0 +1,10 @@ +// 06 - Base Classes and Inheritance\Sealed Classes and Methods +// copyright 2000 Eric Gunnerson +// error +sealed class MyClass +{ + MyClass() {} +} +class MyNewClass : MyClass +{ +} \ No newline at end of file diff --git a/04 - Base Classes and Inheritance/Simple Inheritance/Build1.bat b/04 - Base Classes and Inheritance/Simple Inheritance/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/04 - Base Classes and Inheritance/Simple Inheritance/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/04 - Base Classes and Inheritance/Simple Inheritance/File_1.cs b/04 - Base Classes and Inheritance/Simple Inheritance/File_1.cs new file mode 100644 index 0000000..f897b1f --- /dev/null +++ b/04 - Base Classes and Inheritance/Simple Inheritance/File_1.cs @@ -0,0 +1,60 @@ +// 06 - Base Classes and Inheritance\Simple Inheritance +// copyright 2000 Eric Gunnerson +using System; +class Engineer +{ + public Engineer(string name, float billingRate) + { + this.name = name; + this.billingRate = billingRate; + } + + public float CalculateCharge(float hours) + { + return(hours * billingRate); + } + + public string TypeName() + { + return("Engineer"); + } + + private string name; + protected float billingRate; +} +class CivilEngineer: Engineer +{ + public CivilEngineer(string name, float billingRate) : + base(name, billingRate) + { + } + // new function, because it's different than the + // base version + public new float CalculateCharge(float hours) + { + if (hours < 1.0F) + hours = 1.0F; // minimum charge. + return(hours * billingRate); + } + // new function, because it's different than the + // base version + public new string TypeName() + { + return("Civil Engineer"); + } +} +class Test +{ + public static void Main() + { + Engineer e = new Engineer("George", 15.50F); + CivilEngineer c = new CivilEngineer("Sir John", 40F); + + Console.WriteLine("{0} charge = {1}", + e.TypeName(), + e.CalculateCharge(2F)); + Console.WriteLine("{0} charge = {1}", + c.TypeName(), + c.CalculateCharge(0.75F)); + } +} \ No newline at end of file diff --git a/04 - Base Classes and Inheritance/The Engineer Class/Build1.bat b/04 - Base Classes and Inheritance/The Engineer Class/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/04 - Base Classes and Inheritance/The Engineer Class/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/04 - Base Classes and Inheritance/The Engineer Class/File_1.cs b/04 - Base Classes and Inheritance/The Engineer Class/File_1.cs new file mode 100644 index 0000000..d8fe167 --- /dev/null +++ b/04 - Base Classes and Inheritance/The Engineer Class/File_1.cs @@ -0,0 +1,33 @@ +// 06 - Base Classes and Inheritance\The Engineer Class +// copyright 2000 Eric Gunnerson +using System; +class Engineer +{ + // constructor + public Engineer(string name, float billingRate) + { + this.name = name; + this.billingRate = billingRate; + } + // figure out the charge based on engineer's rate + public float CalculateCharge(float hours) + { + return(hours * billingRate); + } + // return the name of this type + public string TypeName() + { + return("Engineer"); + } + + private string name; + protected float billingRate; +} +class Test +{ + public static void Main() + { + Engineer engineer = new Engineer("Hank", 21.20F); + Console.WriteLine("Name is: {0}", engineer.TypeName()); + } +} \ No newline at end of file diff --git a/04 - Base Classes and Inheritance/Virtual Functions/Build1.bat b/04 - Base Classes and Inheritance/Virtual Functions/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/04 - Base Classes and Inheritance/Virtual Functions/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/04 - Base Classes and Inheritance/Virtual Functions/File_1.cs b/04 - Base Classes and Inheritance/Virtual Functions/File_1.cs new file mode 100644 index 0000000..54266e0 --- /dev/null +++ b/04 - Base Classes and Inheritance/Virtual Functions/File_1.cs @@ -0,0 +1,60 @@ +// 06 - Base Classes and Inheritance\Virtual Functions +// copyright 2000 Eric Gunnerson +using System; +class Engineer +{ + public Engineer(string name, float billingRate) + { + this.name = name; + this.billingRate = billingRate; + } + // function now virtual + virtual public float CalculateCharge(float hours) + { + return(hours * billingRate); + } + // function now virtual + virtual public string TypeName() + { + return("Engineer"); + } + + private string name; + protected float billingRate; +} + +class CivilEngineer: Engineer +{ + public CivilEngineer(string name, float billingRate) : + base(name, billingRate) + { + } + // overrides function in Engineer + override public float CalculateCharge(float hours) + { + if (hours < 1.0F) + hours = 1.0F; // minimum charge. + return(hours * billingRate); + } + // overrides function in Engineer + override public string TypeName() + { + return("Civil Engineer"); + } +} +class Test +{ + public static void Main() + { + Engineer[] earray = new Engineer[2]; + earray[0] = new Engineer("George", 15.50F); + earray[1] = new CivilEngineer("Sir John", 40F); + + Console.WriteLine("{0} charge = {1}", + earray[0].TypeName(), + earray[0].CalculateCharge(2F)); + Console.WriteLine("{0} charge = {1}", + earray[1].TypeName(), + earray[1].CalculateCharge(0.75F)); + } +} \ No newline at end of file diff --git a/05 - Exception Handling/Finally/Build1.bat b/05 - Exception Handling/Finally/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/05 - Exception Handling/Finally/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/05 - Exception Handling/Finally/File_1.cs b/05 - Exception Handling/Finally/File_1.cs new file mode 100644 index 0000000..e8f2dca --- /dev/null +++ b/05 - Exception Handling/Finally/File_1.cs @@ -0,0 +1,55 @@ +// 04 - Exception Handling\Finally +// copyright 2000 Eric Gunnerson +using System; +using System.IO; +class Processor +{ + int count; + int sum; + public int average; + void CalculateAverage(int countAdd, int sumAdd) + { + count += countAdd; + sum += sumAdd; + average = sum / count; + } + public void ProcessFile() + { + FileStream f = new FileStream("data.txt", FileMode.Open); + try + { + StreamReader t = new StreamReader(f); + string line; + while ((line = t.ReadLine()) != null) + { + int count; + int sum; + count = Convert.ToInt32(line); + line = t.ReadLine(); + sum = Convert.ToInt32(line); + CalculateAverage(count, sum); + } + } + // always executed before function exit, even if an + // exception was thrown in the try. + finally + { + f.Close(); + } + } +} +class Test +{ + public static void Main() + { + Processor processor = new Processor(); + try + { + processor.ProcessFile(); + } + catch (Exception e) + { + Console.WriteLine("Exception: {0}", e); + } + } +} \ No newline at end of file diff --git a/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Confuse/Build1.bat b/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Confuse/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Confuse/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Confuse/File_1.cs b/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Confuse/File_1.cs new file mode 100644 index 0000000..1357f14 --- /dev/null +++ b/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Confuse/File_1.cs @@ -0,0 +1,36 @@ +// 04 - Exception Handling\Passing Exceptions on to the Caller\Caller Confuse +// copyright 2000 Eric Gunnerson +using System; +public class Summer +{ + int sum = 0; + int count = 0; + float average; + public void DoAverage() + { + try + { + average = sum / count; + } + catch (DivideByZeroException e) + { + // do some cleanup here + throw; + } + } +} +class Test +{ + public static void Main() + { + Summer summer = new Summer(); + try + { + summer.DoAverage(); + } + catch (Exception e) + { + Console.WriteLine("Exception {0}", e); + } + } +} \ No newline at end of file diff --git a/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Inform/Build1.bat b/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Inform/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Inform/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Inform/File_1.cs b/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Inform/File_1.cs new file mode 100644 index 0000000..010620b --- /dev/null +++ b/05 - Exception Handling/Passing Exceptions on to the Caller/Caller Inform/File_1.cs @@ -0,0 +1,38 @@ +// 04 - Exception Handling\Passing Exceptions on to the Caller\Caller Inform +// copyright 2000 Eric Gunnerson +using System; +public class Summer +{ + int sum = 0; + int count = 0; + float average; + public void DoAverage() + { + try + { + average = sum / count; + } + catch (DivideByZeroException e) + { + // wrap exception in another one, + // adding additional context. + throw (new DivideByZeroException( + "Count is zero in DoAverage()", e)); + } + } +} +public class Test +{ + public static void Main() + { + Summer summer = new Summer(); + try + { + summer.DoAverage(); + } + catch (Exception e) + { + Console.WriteLine("Exception: {0}", e); + } + } +} \ No newline at end of file diff --git a/05 - Exception Handling/The Exception Hierarchy/Build1.bat b/05 - Exception Handling/The Exception Hierarchy/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/05 - Exception Handling/The Exception Hierarchy/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/05 - Exception Handling/The Exception Hierarchy/Build2.bat b/05 - Exception Handling/The Exception Hierarchy/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/05 - Exception Handling/The Exception Hierarchy/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/05 - Exception Handling/The Exception Hierarchy/Build3.bat b/05 - Exception Handling/The Exception Hierarchy/Build3.bat new file mode 100644 index 0000000..b764232 --- /dev/null +++ b/05 - Exception Handling/The Exception Hierarchy/Build3.bat @@ -0,0 +1 @@ +csc File_3.cs diff --git a/05 - Exception Handling/The Exception Hierarchy/File_1.cs b/05 - Exception Handling/The Exception Hierarchy/File_1.cs new file mode 100644 index 0000000..dd5df7e --- /dev/null +++ b/05 - Exception Handling/The Exception Hierarchy/File_1.cs @@ -0,0 +1,24 @@ +// 04 - Exception Handling\The Exception Hierarchy +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + static int Zero = 0; + public static void Main() + { + try + { + int j = 22 / Zero; + } + // catch a specific exception + catch (DivideByZeroException e) + { + Console.WriteLine("DivideByZero {0}", e); + } + // catch any remaining exceptions + catch (Exception e) + { + Console.WriteLine("Exception {0}", e); + } + } +} \ No newline at end of file diff --git a/05 - Exception Handling/The Exception Hierarchy/File_2.cs b/05 - Exception Handling/The Exception Hierarchy/File_2.cs new file mode 100644 index 0000000..53346fc --- /dev/null +++ b/05 - Exception Handling/The Exception Hierarchy/File_2.cs @@ -0,0 +1,24 @@ +// 04 - Exception Handling\The Exception Hierarchy +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + static int Zero = 0; + static void AFunction() + { + int j = 22 / Zero; + // the following line is never executed. + Console.WriteLine("In AFunction()"); + } + public static void Main() + { + try + { + AFunction(); + } + catch (DivideByZeroException e) + { + Console.WriteLine("DivideByZero {0}", e); + } + } +} \ No newline at end of file diff --git a/05 - Exception Handling/The Exception Hierarchy/File_3.cs b/05 - Exception Handling/The Exception Hierarchy/File_3.cs new file mode 100644 index 0000000..75113cb --- /dev/null +++ b/05 - Exception Handling/The Exception Hierarchy/File_3.cs @@ -0,0 +1,32 @@ +// 04 - Exception Handling\The Exception Hierarchy +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + static int Zero = 0; + static void AFunction() + { + try + { + int j = 22 / Zero; + } + // this exception doesn't match + catch (ArgumentOutOfRangeException e) + { + Console.WriteLine("OutOfRangeException: {0}", e); + } + Console.WriteLine("In AFunction()"); + } + public static void Main() + { + try + { + AFunction(); + } + // this exception doesn't match + catch (ArgumentException e) + { + Console.WriteLine("ArgumentException {0}", e); + } + } +} \ No newline at end of file diff --git a/05 - Exception Handling/Trying and Catching/Build1.bat b/05 - Exception Handling/Trying and Catching/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/05 - Exception Handling/Trying and Catching/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/05 - Exception Handling/Trying and Catching/File_1.cs b/05 - Exception Handling/Trying and Catching/File_1.cs new file mode 100644 index 0000000..b6b4339 --- /dev/null +++ b/05 - Exception Handling/Trying and Catching/File_1.cs @@ -0,0 +1,21 @@ +// 04 - Exception Handling\Trying and Catching +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + static int Zero = 0; + public static void Main() + { + // watch for exceptions here + try + { + int j = 22 / Zero; + } + // exceptions that occur in try are transferred here + catch (Exception e) + { + Console.WriteLine("Exception " + e.Message); + } + Console.WriteLine("After catch"); + } +} \ No newline at end of file diff --git a/05 - Exception Handling/User-Defined Exception Classes/Build1.bat b/05 - Exception Handling/User-Defined Exception Classes/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/05 - Exception Handling/User-Defined Exception Classes/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/05 - Exception Handling/User-Defined Exception Classes/File_1.cs b/05 - Exception Handling/User-Defined Exception Classes/File_1.cs new file mode 100644 index 0000000..c1c96c0 --- /dev/null +++ b/05 - Exception Handling/User-Defined Exception Classes/File_1.cs @@ -0,0 +1,45 @@ +// 04 - Exception Handling\User-Defined Exception Classes +// copyright 2000 Eric Gunnerson +using System; +public class CountIsZeroException: ApplicationException +{ + public CountIsZeroException() + { + } + public CountIsZeroException(string message) + : base(message) + { + } + public CountIsZeroException(string message, Exception inner) + : base(message, inner) + { + } +} +public class Summer +{ + int sum = 0; + int count = 0; + float average; + public void DoAverage() + { + if (count == 0) + throw(new CountIsZeroException("Zero count in DoAverage")); + else + average = sum / count; + } +} +class Test +{ + public static void Main() + { + Summer summer = new Summer(); + try + { + summer.DoAverage(); + } + catch (CountIsZeroException e) + { + Console.WriteLine("CountIsZeroException: {0}", e); + } + } +} \ No newline at end of file diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/App.config b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Chapter 6 - accessibility.csproj b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Chapter 6 - accessibility.csproj new file mode 100644 index 0000000..b60587b --- /dev/null +++ b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Chapter 6 - accessibility.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {43EF0584-9C86-4CFE-8A5F-31C0F5C93DF5} + Exe + Properties + Chapter_6___accessibility + Chapter 6 - accessibility + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Chapter 6 - accessibility.sln b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Chapter 6 - accessibility.sln new file mode 100644 index 0000000..1e11c4f --- /dev/null +++ b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Chapter 6 - accessibility.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chapter 6 - accessibility", "Chapter 6 - accessibility.csproj", "{43EF0584-9C86-4CFE-8A5F-31C0F5C93DF5}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {43EF0584-9C86-4CFE-8A5F-31C0F5C93DF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {43EF0584-9C86-4CFE-8A5F-31C0F5C93DF5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {43EF0584-9C86-4CFE-8A5F-31C0F5C93DF5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {43EF0584-9C86-4CFE-8A5F-31C0F5C93DF5}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Chapter 6 - accessibility.v11.suo b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Chapter 6 - accessibility.v11.suo new file mode 100644 index 0000000..0dcb12a Binary files /dev/null and b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Chapter 6 - accessibility.v11.suo differ diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Logger.cs b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Logger.cs new file mode 100644 index 0000000..4d05551 --- /dev/null +++ b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Logger.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chapter_6___accessibility +{ +public class Logger +{ + public static void LogMessage(string message, bool includeDateAndTime) + { + if (includeDateAndTime) + { + Console.WriteLine(DateTime.Now); + } + Console.WriteLine(message); + } +} +} diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Program.cs b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Program.cs new file mode 100644 index 0000000..5226f8d --- /dev/null +++ b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Program.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chapter_6___accessibility +{ + class Program + { + static void Main(string[] args) + { + Logger.LogMessage("Warp initiated", includeDateAndTime: true); + } + } +} diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Properties/AssemblyInfo.cs b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..001db78 --- /dev/null +++ b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Chapter 6 - accessibility")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Chapter 6 - accessibility")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("f2ce8b83-f141-4993-a429-6a9a6695a286")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.exe b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.exe new file mode 100644 index 0000000..6209e17 Binary files /dev/null and b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.exe differ diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.exe.config b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.exe.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.pdb b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.pdb new file mode 100644 index 0000000..1fdb8a7 Binary files /dev/null and b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.pdb differ diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.vshost.exe b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.vshost.exe new file mode 100644 index 0000000..212bd7f Binary files /dev/null and b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.vshost.exe differ diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.vshost.exe.config b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.vshost.exe.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/bin/Debug/Chapter 6 - accessibility.vshost.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.csproj.FileListAbsolute.txt b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..44f31b8 --- /dev/null +++ b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.csproj.FileListAbsolute.txt @@ -0,0 +1,6 @@ +d:\data\booknew\chapters\code\Chapter 6 - accessibility\bin\Debug\Chapter 6 - accessibility.exe.config +d:\data\booknew\chapters\code\Chapter 6 - accessibility\bin\Debug\Chapter 6 - accessibility.exe +d:\data\booknew\chapters\code\Chapter 6 - accessibility\bin\Debug\Chapter 6 - accessibility.pdb +d:\data\booknew\chapters\code\Chapter 6 - accessibility\obj\Debug\Chapter 6 - accessibility.csprojResolveAssemblyReference.cache +d:\data\booknew\chapters\code\Chapter 6 - accessibility\obj\Debug\Chapter 6 - accessibility.exe +d:\data\booknew\chapters\code\Chapter 6 - accessibility\obj\Debug\Chapter 6 - accessibility.pdb diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.csprojResolveAssemblyReference.cache b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.csprojResolveAssemblyReference.cache new file mode 100644 index 0000000..ff54045 Binary files /dev/null and b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.csprojResolveAssemblyReference.cache differ diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.exe b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.exe new file mode 100644 index 0000000..6209e17 Binary files /dev/null and b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.exe differ diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.pdb b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.pdb new file mode 100644 index 0000000..1fdb8a7 Binary files /dev/null and b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/Chapter 6 - accessibility.pdb differ diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..84029c3 Binary files /dev/null and b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs new file mode 100644 index 0000000..e69de29 diff --git a/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs b/06 - Member Accessibility and Overloading/Chapter 6 - accessibility/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs new file mode 100644 index 0000000..e69de29 diff --git a/06 - Member Accessibility and Overloading/Method Overloading/Better Conversions/Build1.bat b/06 - Member Accessibility and Overloading/Method Overloading/Better Conversions/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/06 - Member Accessibility and Overloading/Method Overloading/Better Conversions/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/06 - Member Accessibility and Overloading/Method Overloading/Better Conversions/File_1.cs b/06 - Member Accessibility and Overloading/Method Overloading/Better Conversions/File_1.cs new file mode 100644 index 0000000..51bf5da --- /dev/null +++ b/06 - Member Accessibility and Overloading/Method Overloading/Better Conversions/File_1.cs @@ -0,0 +1,28 @@ +// 07 - Member Accessibility and Overloading\Method Overloading\Better Conversions +// copyright 2000 Eric Gunnerson +using System; +public class MyClass +{ + public void Process(long value) + { + Console.WriteLine("Process(long): {0}", value); + } + public void Process(short value) + { + Console.WriteLine("Process(short): {0}", value); + } +} + +class Test +{ + public static void Main() + { + MyClass myClass = new MyClass(); + + int i = 12; + myClass.Process(i); + + sbyte s = 12; + myClass.Process(s); + } +} \ No newline at end of file diff --git a/06 - Member Accessibility and Overloading/Method Overloading/Method Hiding/Build1.bat b/06 - Member Accessibility and Overloading/Method Overloading/Method Hiding/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/06 - Member Accessibility and Overloading/Method Overloading/Method Hiding/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/06 - Member Accessibility and Overloading/Method Overloading/Method Hiding/File_1.cs b/06 - Member Accessibility and Overloading/Method Overloading/Method Hiding/File_1.cs new file mode 100644 index 0000000..93508e0 --- /dev/null +++ b/06 - Member Accessibility and Overloading/Method Overloading/Method Hiding/File_1.cs @@ -0,0 +1,32 @@ +// 07 - Member Accessibility and Overloading\Method Overloading\Method Hiding +// copyright 2000 Eric Gunnerson +using System; +public class Base +{ + public void Process(short value) + { + Console.WriteLine("Base.Process(short): {0}", value); + } +} +public class Derived: Base +{ + public void Process(int value) + { + Console.WriteLine("Derived.Process(int): {0}", value); + } + + public void Process(string value) + { + Console.WriteLine("Derived.Process(string): {0}", value); + } +} +class Test +{ + public static void Main() + { + Derived d = new Derived(); + short i = 12; + d.Process(i); + ((Base) d).Process(i); + } +} \ No newline at end of file diff --git a/06 - Member Accessibility and Overloading/The Interaction of Class and Member Accessibility/Build1.bat b/06 - Member Accessibility and Overloading/The Interaction of Class and Member Accessibility/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/06 - Member Accessibility and Overloading/The Interaction of Class and Member Accessibility/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/06 - Member Accessibility and Overloading/The Interaction of Class and Member Accessibility/File_1.cs b/06 - Member Accessibility and Overloading/The Interaction of Class and Member Accessibility/File_1.cs new file mode 100644 index 0000000..531cf7f --- /dev/null +++ b/06 - Member Accessibility and Overloading/The Interaction of Class and Member Accessibility/File_1.cs @@ -0,0 +1,8 @@ +// 07 - Member Accessibility and Overloading\The Interaction of Class and Member Accessibility +// copyright 2000 Eric Gunnerson +internal class MyHelperClass +{ + public void PublicFunction() {} + internal void InternalFunction() {} + protected void ProtectedFunction() {} +} \ No newline at end of file diff --git a/06 - Member Accessibility and Overloading/Using Internal on Members/Build1.bat b/06 - Member Accessibility and Overloading/Using Internal on Members/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/06 - Member Accessibility and Overloading/Using Internal on Members/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/06 - Member Accessibility and Overloading/Using Internal on Members/File_1.cs b/06 - Member Accessibility and Overloading/Using Internal on Members/File_1.cs new file mode 100644 index 0000000..fb1d61d --- /dev/null +++ b/06 - Member Accessibility and Overloading/Using Internal on Members/File_1.cs @@ -0,0 +1,40 @@ +// 07 - Member Accessibility and Overloading\Using Internal on Members +// copyright 2000 Eric Gunnerson +public class DrawingObjectGroup +{ + public DrawingObjectGroup() + { + objects = new DrawingObject[10]; + objectCount = 0; + } + public void AddObject(DrawingObject obj) + { + if (objectCount < 10) + { + objects[objectCount] = obj; + objectCount++; + } + } + public void Render() + { + for (int i = 0; i < objectCount; i++) + { + objects[i].Render(); + } + } + + DrawingObject[] objects; + int objectCount; +} +public class DrawingObject +{ + internal void Render() {} +} +class Test +{ + public static void Main() + { + DrawingObjectGroup group = new DrawingObjectGroup(); + group.AddObject(new DrawingObject()); + } +} \ No newline at end of file diff --git a/06 - Member Accessibility and Overloading/Variable-Length Parameter Lists/Build1.bat b/06 - Member Accessibility and Overloading/Variable-Length Parameter Lists/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/06 - Member Accessibility and Overloading/Variable-Length Parameter Lists/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/06 - Member Accessibility and Overloading/Variable-Length Parameter Lists/File_1.cs b/06 - Member Accessibility and Overloading/Variable-Length Parameter Lists/File_1.cs new file mode 100644 index 0000000..46006a9 --- /dev/null +++ b/06 - Member Accessibility and Overloading/Variable-Length Parameter Lists/File_1.cs @@ -0,0 +1,42 @@ +// 07 - Member Accessibility and Overloading\Variable-Length Parameter Lists +// copyright 2000 Eric Gunnerson +using System; +class Port +{ + // version with a single object parameter + public void Write(string label, object arg) + { + WriteString(label); + WriteString(arg.ToString()); + } + // version with an array of object parameters + public void Write(string label, params object[] args) + { + WriteString(label); + foreach (object o in args) + { + WriteString(o.ToString()); + } + } + void WriteString(string str) + { + // writes string to the port here + Console.WriteLine("Port debug: {0}", str); + } +} + +class Test +{ + public static void Main() + { + Port port = new Port(); + port.Write("Single Test", "Port ok"); + port.Write("Port Test: ", "a", "b", 12, 14.2); + object[] arr = new object[4]; + arr[0] = "The"; + arr[1] = "answer"; + arr[2] = "is"; + arr[3] = 42; + port.Write("What is the answer?", arr); + } +} \ No newline at end of file diff --git a/07 - Other Class Details/Constants/Build1.bat b/07 - Other Class Details/Constants/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/07 - Other Class Details/Constants/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/07 - Other Class Details/Constants/File_1.cs b/07 - Other Class Details/Constants/File_1.cs new file mode 100644 index 0000000..b3c2858 --- /dev/null +++ b/07 - Other Class Details/Constants/File_1.cs @@ -0,0 +1,25 @@ +// 08 - Other Class Details\Constants +// copyright 2000 Eric Gunnerson +using System; +enum MyEnum +{ + Jet +} +class LotsOLiterals +{ + // const items can't be changed. + // const implies static. + public const int value1 = 33; + public const string value2 = "Hello"; + public const MyEnum value3 = MyEnum.Jet; +} +class Test +{ + public static void Main() + { + Console.WriteLine("{0} {1} {2}", + LotsOLiterals.value1, + LotsOLiterals.value2, + LotsOLiterals.value3); + } +} \ No newline at end of file diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Build1.bat b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Build2.bat b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/File_1.cs b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/File_1.cs new file mode 100644 index 0000000..c3e452e --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/File_1.cs @@ -0,0 +1,32 @@ +// 08 - Other Class Details\Creation, Initialization, Destruction\Constructors +// copyright 2000 Eric Gunnerson +using System; +public class BaseClass +{ + public BaseClass(int x) + { + this.x = x; + } + public int X + { + get + { + return(x); + } + } + int x; +} +public class Derived: BaseClass +{ + public Derived(int x): base(x) + { + } +} +class Test +{ + public static void Main() + { + Derived d = new Derived(15); + Console.WriteLine("X = {0}", d.X); + } +} \ No newline at end of file diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/File_2.cs b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/File_2.cs new file mode 100644 index 0000000..a109706 --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/File_2.cs @@ -0,0 +1,38 @@ +// 08 - Other Class Details\Creation, Initialization, Destruction\Constructors +// copyright 2000 Eric Gunnerson +using System; +class MyObject +{ + public MyObject(int x) + { + this.x = x; + } + public MyObject(int x, int y): this(x) + { + this.y = y; + } + public int X + { + get + { + return(x); + } + } + public int Y + { + get + { + return(y); + } + } + int x; + int y; +} +class Test +{ + public static void Main() + { + MyObject my = new MyObject(10, 20); + Console.WriteLine("x = {0}, y = {1}", my.X, my.Y); + } +} \ No newline at end of file diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Private constructors/Build1.bat b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Private constructors/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Private constructors/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Private constructors/File_1.cs b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Private constructors/File_1.cs new file mode 100644 index 0000000..75c47ac --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Constructors/Private constructors/File_1.cs @@ -0,0 +1,22 @@ +// 08 - Other Class Details\Creation, Initialization, Destruction\Constructors\Private constructors +// copyright 2000 Eric Gunnerson +public class SystemInfo +{ + static SystemInfo cache = null; + static object cacheLock = new object(); + private SystemInfo() + { + // useful stuff here + } + + public static SystemInfo GetSystemInfo() + { + lock(cacheLock) + { + if (cache == null) + cache = new SystemInfo(); + + return(cache); + } + } +} \ No newline at end of file diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Initialization/Build1.bat b/07 - Other Class Details/Creation, Initialization, Destruction/Initialization/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Initialization/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Initialization/File_1.cs b/07 - Other Class Details/Creation, Initialization, Destruction/Initialization/File_1.cs new file mode 100644 index 0000000..6e65af8 --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Initialization/File_1.cs @@ -0,0 +1,16 @@ +// 08 - Other Class Details\Creation, Initialization, Destruction\Initialization +// copyright 2000 Eric Gunnerson +public class Parser // Support class +{ + public Parser(int number) + { + this.number = number; + } + int number; +} +class MyClass +{ + public int counter = 100; + public string heading = "Top"; + private Parser parser = new Parser(100); +} \ No newline at end of file diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/Build1.bat b/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/Build2.bat b/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/File_1.cs b/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/File_1.cs new file mode 100644 index 0000000..483d9a7 --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/File_1.cs @@ -0,0 +1,26 @@ +// 08 - Other Class Details\Creation, Initialization, Destruction\Managing Non-Memory Resources +// copyright 2000 Eric Gunnerson +using System; +using System.Runtime.InteropServices; + +class ResourceWrapper +{ + int handle = 0; + + public ResourceWrapper() + { + handle = GetWindowsResource(); + } + + ~ResourceWrapper() + { + FreeWindowsResource(handle); + handle = 0; + } + + [DllImport("dll.dll")] + static extern int GetWindowsResource(); + + [DllImport("dll.dll")] + static extern void FreeWindowsResource(int handle); +} \ No newline at end of file diff --git a/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/File_2.cs b/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/File_2.cs new file mode 100644 index 0000000..23ab6b4 --- /dev/null +++ b/07 - Other Class Details/Creation, Initialization, Destruction/Managing Non-Memory Resources/File_2.cs @@ -0,0 +1,43 @@ +// 08 - Other Class Details\Creation, Initialization, Destruction\Managing Non-Memory Resources +// copyright 2000 Eric Gunnerson +using System; +using System.Runtime.InteropServices; + +class ResourceWrapper: IDisposable +{ + int handle = 0; + + public ResourceWrapper() + { + handle = GetWindowsResource(); + } + + // does cleanup for this object only + void DoDispose() + { + FreeWindowsResource(handle); + handle = 0; + } + + ~ResourceWrapper() + { + DoDispose(); + } + + // dispose cleans up its object, and any objects it holds + // that also implement IDisposable. + public void Dispose() + { + DoDispose(); + // call Dispose() on our base class (if necessary), and + // on any other resources we hold that implement IDisposable + + GC.SuppressFinalize(this); + } + + [DllImport("dll.dll")] + static extern int GetWindowsResource(); + + [DllImport("dll.dll")] + static extern void FreeWindowsResource(int handle); +} \ No newline at end of file diff --git a/07 - Other Class Details/Nested Classes/Build1.bat b/07 - Other Class Details/Nested Classes/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/07 - Other Class Details/Nested Classes/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/07 - Other Class Details/Nested Classes/Build2.bat b/07 - Other Class Details/Nested Classes/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/07 - Other Class Details/Nested Classes/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/07 - Other Class Details/Nested Classes/File_1.cs b/07 - Other Class Details/Nested Classes/File_1.cs new file mode 100644 index 0000000..99921cf --- /dev/null +++ b/07 - Other Class Details/Nested Classes/File_1.cs @@ -0,0 +1,10 @@ +// 08 - Other Class Details\Nested Classes +// copyright 2000 Eric Gunnerson +public class Parser +{ + Token[] tokens; +} +public class Token +{ + string name; +} \ No newline at end of file diff --git a/07 - Other Class Details/Nested Classes/File_2.cs b/07 - Other Class Details/Nested Classes/File_2.cs new file mode 100644 index 0000000..206bb48 --- /dev/null +++ b/07 - Other Class Details/Nested Classes/File_2.cs @@ -0,0 +1,10 @@ +// 08 - Other Class Details\Nested Classes +// copyright 2000 Eric Gunnerson +public class Parser +{ + Token[] tokens; + private class Token + { + string name; + } +} \ No newline at end of file diff --git a/07 - Other Class Details/OtherClassDetails/OtherClassDetails.csproj b/07 - Other Class Details/OtherClassDetails/OtherClassDetails.csproj new file mode 100644 index 0000000..b713b02 --- /dev/null +++ b/07 - Other Class Details/OtherClassDetails/OtherClassDetails.csproj @@ -0,0 +1,57 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {21150F8E-372C-4BE5-80D8-6FFC47EE01E4} + Exe + Properties + ConsoleApplication1 + OtherClassDetails + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/07 - Other Class Details/OtherClassDetails/OtherClassDetails.csproj.user b/07 - Other Class Details/OtherClassDetails/OtherClassDetails.csproj.user new file mode 100644 index 0000000..ace9a86 --- /dev/null +++ b/07 - Other Class Details/OtherClassDetails/OtherClassDetails.csproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/07 - Other Class Details/OtherClassDetails/OtherClassDetails.sln b/07 - Other Class Details/OtherClassDetails/OtherClassDetails.sln new file mode 100644 index 0000000..e1fdff1 --- /dev/null +++ b/07 - Other Class Details/OtherClassDetails/OtherClassDetails.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C# Express 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OtherClassDetails", "OtherClassDetails.csproj", "{21150F8E-372C-4BE5-80D8-6FFC47EE01E4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {21150F8E-372C-4BE5-80D8-6FFC47EE01E4}.Debug|x86.ActiveCfg = Debug|x86 + {21150F8E-372C-4BE5-80D8-6FFC47EE01E4}.Debug|x86.Build.0 = Debug|x86 + {21150F8E-372C-4BE5-80D8-6FFC47EE01E4}.Release|x86.ActiveCfg = Release|x86 + {21150F8E-372C-4BE5-80D8-6FFC47EE01E4}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/07 - Other Class Details/OtherClassDetails/OtherClassDetails.suo b/07 - Other Class Details/OtherClassDetails/OtherClassDetails.suo new file mode 100644 index 0000000..34a7fb6 Binary files /dev/null and b/07 - Other Class Details/OtherClassDetails/OtherClassDetails.suo differ diff --git a/07 - Other Class Details/OtherClassDetails/Program.cs b/07 - Other Class Details/OtherClassDetails/Program.cs new file mode 100644 index 0000000..2bf8910 --- /dev/null +++ b/07 - Other Class Details/OtherClassDetails/Program.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OtherLanguageDetails +{ + class Program + { + static void Main(string[] args) + { + Original(); + Method(); + ClassHelperMethod(); + ExtensionMethod(); + } + + static void Original() + { +string test = "#Name#,#Date#,#Age#,#Salary#"; + +string[] fieldArray = test.Split(','); + +List fields = new List(); + +foreach (string field in fieldArray) +{ + fields.Add(field.Replace("#", "")); +} + + foreach (string field in fields) + { + Console.WriteLine(field); + } + } + + static void Method() + { +string test = "#Name#,#Date#,#Age#,#Salary#"; + +List fields = ExtractFields(test); + +foreach (string field in fields) +{ + Console.WriteLine(field); +} + } + + static void ClassHelperMethod() + { + string test = "#Name#,#Date#,#Age#,#Salary#"; + +List fields = StringHelper.ExtractFields(test); + + foreach (string field in fields) + { + Console.WriteLine(field); + } + } + + static void ExtensionMethod() + { + string test = "#Name#,#Date#,#Age#,#Salary#"; + + List fields = test.ExtractFields(); + + foreach (string field in fields) + { + Console.WriteLine(field); + } + } + +static List ExtractFields(string fieldString) +{ + string[] fieldArray = fieldString.Split(','); + + List fields = new List(); + + foreach (string field in fieldArray) + { + fields.Add(field.Replace("#", "")); + } + + return fields; +} + } + + public static class StringHelper + { + public static List ExtractFields(string fieldString) + { + string[] fieldArray = fieldString.Split(','); + + List fields = new List(); + + foreach (string field in fieldArray) + { + fields.Add(field.Replace("#", "")); + } + + return fields; + } + } + + public static class StringExtensions + { + public static List ExtractFields(this string fieldString) + { + string[] fieldArray = fieldString.Split(','); + + List fields = new List(); + + foreach (string field in fieldArray) + { + fields.Add(field.Replace("#", "")); + } + + return fields; + } + } +} diff --git a/07 - Other Class Details/OtherClassDetails/Properties/AssemblyInfo.cs b/07 - Other Class Details/OtherClassDetails/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b4bd104 --- /dev/null +++ b/07 - Other Class Details/OtherClassDetails/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConsoleApplication1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ConsoleApplication1")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("259d94c5-1216-41a2-90c0-4486548d3304")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/07 - Other Class Details/OtherClassDetails/bin/Debug/ConsoleApplication1.vshost.exe b/07 - Other Class Details/OtherClassDetails/bin/Debug/ConsoleApplication1.vshost.exe new file mode 100644 index 0000000..bb84a51 Binary files /dev/null and b/07 - Other Class Details/OtherClassDetails/bin/Debug/ConsoleApplication1.vshost.exe differ diff --git a/07 - Other Class Details/OtherClassDetails/bin/Debug/ConsoleApplication1.vshost.exe.manifest b/07 - Other Class Details/OtherClassDetails/bin/Debug/ConsoleApplication1.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/07 - Other Class Details/OtherClassDetails/bin/Debug/ConsoleApplication1.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/07 - Other Class Details/OtherClassDetails/bin/Release/ConsoleApplication1.exe b/07 - Other Class Details/OtherClassDetails/bin/Release/ConsoleApplication1.exe new file mode 100644 index 0000000..8e1bc13 Binary files /dev/null and b/07 - Other Class Details/OtherClassDetails/bin/Release/ConsoleApplication1.exe differ diff --git a/07 - Other Class Details/OtherClassDetails/bin/Release/ConsoleApplication1.pdb b/07 - Other Class Details/OtherClassDetails/bin/Release/ConsoleApplication1.pdb new file mode 100644 index 0000000..019e152 Binary files /dev/null and b/07 - Other Class Details/OtherClassDetails/bin/Release/ConsoleApplication1.pdb differ diff --git a/07 - Other Class Details/OtherClassDetails/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/07 - Other Class Details/OtherClassDetails/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..1faf597 Binary files /dev/null and b/07 - Other Class Details/OtherClassDetails/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/07 - Other Class Details/OtherClassDetails/obj/x86/Release/ConsoleApplication1.csproj.FileListAbsolute.txt b/07 - Other Class Details/OtherClassDetails/obj/x86/Release/ConsoleApplication1.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..28be997 --- /dev/null +++ b/07 - Other Class Details/OtherClassDetails/obj/x86/Release/ConsoleApplication1.csproj.FileListAbsolute.txt @@ -0,0 +1,5 @@ +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\ConsoleApplication1\bin\Release\ConsoleApplication1.exe +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\ConsoleApplication1\bin\Release\ConsoleApplication1.pdb +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\ConsoleApplication1\obj\x86\Release\ResolveAssemblyReference.cache +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\ConsoleApplication1\obj\x86\Release\ConsoleApplication1.exe +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\ConsoleApplication1\obj\x86\Release\ConsoleApplication1.pdb diff --git a/07 - Other Class Details/OtherClassDetails/obj/x86/Release/ConsoleApplication1.exe b/07 - Other Class Details/OtherClassDetails/obj/x86/Release/ConsoleApplication1.exe new file mode 100644 index 0000000..8e1bc13 Binary files /dev/null and b/07 - Other Class Details/OtherClassDetails/obj/x86/Release/ConsoleApplication1.exe differ diff --git a/07 - Other Class Details/OtherClassDetails/obj/x86/Release/ConsoleApplication1.pdb b/07 - Other Class Details/OtherClassDetails/obj/x86/Release/ConsoleApplication1.pdb new file mode 100644 index 0000000..019e152 Binary files /dev/null and b/07 - Other Class Details/OtherClassDetails/obj/x86/Release/ConsoleApplication1.pdb differ diff --git a/07 - Other Class Details/OtherClassDetails/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache b/07 - Other Class Details/OtherClassDetails/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..cd24a59 Binary files /dev/null and b/07 - Other Class Details/OtherClassDetails/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/07 - Other Class Details/Partial/Build1.bat b/07 - Other Class Details/Partial/Build1.bat new file mode 100644 index 0000000..7cbdfb3 --- /dev/null +++ b/07 - Other Class Details/Partial/Build1.bat @@ -0,0 +1 @@ +csc Util.cs Util2.cs diff --git a/07 - Other Class Details/Partial/Util.cs b/07 - Other Class Details/Partial/Util.cs new file mode 100644 index 0000000..3775d13 --- /dev/null +++ b/07 - Other Class Details/Partial/Util.cs @@ -0,0 +1,22 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace OtherClassDetails +{ + partial class Util + { + } + + partial class Util4 + { + } + + partial class Util4 + { + } +} diff --git a/07 - Other Class Details/Partial/Util2.cs b/07 - Other Class Details/Partial/Util2.cs new file mode 100644 index 0000000..c6bd1eb --- /dev/null +++ b/07 - Other Class Details/Partial/Util2.cs @@ -0,0 +1,25 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace OtherClassDetails +{ + partial class Util + { + } + + public class MyBase{} + + partial class MyPartialClass : MyBase + { + public void Dispose() { } + } + + partial class MyPartialClass : IDisposable { } + + partial struct MyInt { } +} diff --git a/07 - Other Class Details/Readonly Fields/Build1.bat b/07 - Other Class Details/Readonly Fields/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/07 - Other Class Details/Readonly Fields/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/07 - Other Class Details/Readonly Fields/Build2.bat b/07 - Other Class Details/Readonly Fields/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/07 - Other Class Details/Readonly Fields/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/07 - Other Class Details/Readonly Fields/Build3.bat b/07 - Other Class Details/Readonly Fields/Build3.bat new file mode 100644 index 0000000..b764232 --- /dev/null +++ b/07 - Other Class Details/Readonly Fields/Build3.bat @@ -0,0 +1 @@ +csc File_3.cs diff --git a/07 - Other Class Details/Readonly Fields/File_1.cs b/07 - Other Class Details/Readonly Fields/File_1.cs new file mode 100644 index 0000000..4faa837 --- /dev/null +++ b/07 - Other Class Details/Readonly Fields/File_1.cs @@ -0,0 +1,27 @@ +// 08 - Other Class Details\Readonly Fields +// copyright 2000 Eric Gunnerson +// error +class Color +{ + public Color(int red, int green, int blue) + { + this.red = red; + this.green = green; + this.blue = blue; + } + + int red; + int green; + int blue; + // call to new can't be used with static + public const Color Red = new Color(255, 0, 0); + public const Color Green = new Color(0, 255, 0); + public const Color Blue = new Color(0, 0, 255); +} +class Test +{ + static void Main() + { + Color background = Color.Red; + } +} \ No newline at end of file diff --git a/07 - Other Class Details/Readonly Fields/File_2.cs b/07 - Other Class Details/Readonly Fields/File_2.cs new file mode 100644 index 0000000..df4711c --- /dev/null +++ b/07 - Other Class Details/Readonly Fields/File_2.cs @@ -0,0 +1,34 @@ +// 08 - Other Class Details\Readonly Fields +// copyright 2000 Eric Gunnerson +class Color +{ + public Color(int red, int green, int blue) + { + this.red = red; + this.green = green; + this.blue = blue; + } + + int red; + int green; + int blue; + + public static readonly Color Red; + public static readonly Color Green; + public static readonly Color Blue; + + // static constructor + static Color() + { + Red = new Color(255, 0, 0); + Green = new Color(0, 255, 0); + Blue = new Color(0, 0, 255); + } +} +class Test +{ + static void Main() + { + Color background = Color.Red; + } +} \ No newline at end of file diff --git a/07 - Other Class Details/Readonly Fields/File_3.cs b/07 - Other Class Details/Readonly Fields/File_3.cs new file mode 100644 index 0000000..3d28b61 --- /dev/null +++ b/07 - Other Class Details/Readonly Fields/File_3.cs @@ -0,0 +1,47 @@ +// 08 - Other Class Details\Readonly Fields +// copyright 2000 Eric Gunnerson +class Color +{ + public Color(int red, int green, int blue) + { + this.red = red; + this.green = green; + this.blue = blue; + } + + public enum PredefinedEnum + { + Red, + Blue, + Green + } + public static Color GetPredefinedColor( + PredefinedEnum pre) + { + switch (pre) + { + case PredefinedEnum.Red: + return(new Color(255, 0, 0)); + + case PredefinedEnum.Green: + return(new Color(0, 255, 0)); + + case PredefinedEnum.Blue: + return(new Color(0, 0, 255)); + + default: + return(new Color(0, 0, 0)); + } + } + int red; + int blue; + int green; +} +class Test +{ + static void Main() + { + Color background = + Color.GetPredefinedColor(Color.PredefinedEnum.Blue); + } +} \ No newline at end of file diff --git a/07 - Other Class Details/Static Constructors/Build1.bat b/07 - Other Class Details/Static Constructors/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/07 - Other Class Details/Static Constructors/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/07 - Other Class Details/Static Constructors/File_1.cs b/07 - Other Class Details/Static Constructors/File_1.cs new file mode 100644 index 0000000..9b51ff3 --- /dev/null +++ b/07 - Other Class Details/Static Constructors/File_1.cs @@ -0,0 +1,10 @@ +// 08 - Other Class Details\Static Constructors +// copyright 2000 Eric Gunnerson +using System; +class MyClass +{ + static MyClass() + { + Console.WriteLine("MyClass is initializing"); + } +} \ No newline at end of file diff --git a/07 - Other Class Details/Static Fields/Build1.bat b/07 - Other Class Details/Static Fields/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/07 - Other Class Details/Static Fields/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/07 - Other Class Details/Static Fields/File_1.cs b/07 - Other Class Details/Static Fields/File_1.cs new file mode 100644 index 0000000..5efb76a --- /dev/null +++ b/07 - Other Class Details/Static Fields/File_1.cs @@ -0,0 +1,21 @@ +// 08 - Other Class Details\Static Fields +// copyright 2000 Eric Gunnerson +using System; +class MyClass +{ + public MyClass() + { + instanceCount++; + } + public static int instanceCount = 0; +} +class Test +{ + public static void Main() + { + MyClass my = new MyClass(); + Console.WriteLine(MyClass.instanceCount); + MyClass my2 = new MyClass(); + Console.WriteLine(MyClass.instanceCount); + } +} \ No newline at end of file diff --git a/07 - Other Class Details/Static Member Functions/Build1.bat b/07 - Other Class Details/Static Member Functions/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/07 - Other Class Details/Static Member Functions/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/07 - Other Class Details/Static Member Functions/File_1.cs b/07 - Other Class Details/Static Member Functions/File_1.cs new file mode 100644 index 0000000..65e4cde --- /dev/null +++ b/07 - Other Class Details/Static Member Functions/File_1.cs @@ -0,0 +1,23 @@ +// 08 - Other Class Details\Static Member Functions +// copyright 2000 Eric Gunnerson +using System; +class MyClass +{ + public MyClass() + { + instanceCount++; + } + public static int GetInstanceCount() + { + return(instanceCount); + } + static int instanceCount = 0; +} +class Test +{ + public static void Main() + { + MyClass my = new MyClass(); + Console.WriteLine(MyClass.GetInstanceCount()); + } +} \ No newline at end of file diff --git a/08 - Structs (Value Types)/A Point Struct/Build1.bat b/08 - Structs (Value Types)/A Point Struct/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/08 - Structs (Value Types)/A Point Struct/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/08 - Structs (Value Types)/A Point Struct/File_1.cs b/08 - Structs (Value Types)/A Point Struct/File_1.cs new file mode 100644 index 0000000..ba9faf4 --- /dev/null +++ b/08 - Structs (Value Types)/A Point Struct/File_1.cs @@ -0,0 +1,26 @@ +// 09 - Structs (Value Types)\A Point Struct +// copyright 2000 Eric Gunnerson +using System; +struct Point +{ + public Point(int x, int y) + { + this.x = x; + this.y = y; + } + public override string ToString() + { + return(String.Format("({0}, {1})", x, y)); + } + + public int x; + public int y; +} +class Test +{ + public static void Main() + { + Point start = new Point(5, 5); + Console.WriteLine("Start: {0}", start); + } +} \ No newline at end of file diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/App.config b/08 - Structs (Value Types)/Chapter 8 - Structs/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/08 - Structs (Value Types)/Chapter 8 - Structs/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/Chapter 8 - Structs.csproj b/08 - Structs (Value Types)/Chapter 8 - Structs/Chapter 8 - Structs.csproj new file mode 100644 index 0000000..edf1b18 --- /dev/null +++ b/08 - Structs (Value Types)/Chapter 8 - Structs/Chapter 8 - Structs.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {B8E2962E-78B9-4263-8569-1EA6277D21F8} + Exe + Properties + Chapter_8___Structs + Chapter 8 - Structs + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/Chapter 8 - Structs.sln b/08 - Structs (Value Types)/Chapter 8 - Structs/Chapter 8 - Structs.sln new file mode 100644 index 0000000..e7c2688 --- /dev/null +++ b/08 - Structs (Value Types)/Chapter 8 - Structs/Chapter 8 - Structs.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chapter 8 - Structs", "Chapter 8 - Structs.csproj", "{B8E2962E-78B9-4263-8569-1EA6277D21F8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B8E2962E-78B9-4263-8569-1EA6277D21F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B8E2962E-78B9-4263-8569-1EA6277D21F8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B8E2962E-78B9-4263-8569-1EA6277D21F8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B8E2962E-78B9-4263-8569-1EA6277D21F8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/Chapter 8 - Structs.v11.suo b/08 - Structs (Value Types)/Chapter 8 - Structs/Chapter 8 - Structs.v11.suo new file mode 100644 index 0000000..5f19f5e Binary files /dev/null and b/08 - Structs (Value Types)/Chapter 8 - Structs/Chapter 8 - Structs.v11.suo differ diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/Point.cs b/08 - Structs (Value Types)/Chapter 8 - Structs/Point.cs new file mode 100644 index 0000000..628b167 --- /dev/null +++ b/08 - Structs (Value Types)/Chapter 8 - Structs/Point.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +struct Point +{ + public int m_x; + public int m_y; + + public Point(int x, int y) + { + m_x = x; + m_y = y; + } + public override string ToString() + { + return String.Format("({0}, {1})", m_x, m_y); + } +} diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/PointHolder.cs b/08 - Structs (Value Types)/Chapter 8 - Structs/PointHolder.cs new file mode 100644 index 0000000..143ac6d --- /dev/null +++ b/08 - Structs (Value Types)/Chapter 8 - Structs/PointHolder.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chapter_8___Structs +{ +class PointHolder +{ + public PointHolder(Point point) + { + Current = point; + } + + public Point Current; +} +} diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/Program.cs b/08 - Structs (Value Types)/Chapter 8 - Structs/Program.cs new file mode 100644 index 0000000..547c7a6 --- /dev/null +++ b/08 - Structs (Value Types)/Chapter 8 - Structs/Program.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chapter_8___Structs +{ + class Program + { +static void Main(string[] args) +{ + Example(); +} + +static void Example() +{ + Point point = new Point(10, 15); + PointHolder pointHolder = new PointHolder(point); + + Console.WriteLine(pointHolder.Current); + + Point current = pointHolder.Current; + current.m_x = 500; + + Console.WriteLine(pointHolder.Current); +} + } +} diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/Properties/AssemblyInfo.cs b/08 - Structs (Value Types)/Chapter 8 - Structs/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8ba8c2e --- /dev/null +++ b/08 - Structs (Value Types)/Chapter 8 - Structs/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Chapter 8 - Structs")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Chapter 8 - Structs")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a6827f51-72c9-4a62-8191-10ea71d884f5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.exe b/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.exe new file mode 100644 index 0000000..3fed961 Binary files /dev/null and b/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.exe differ diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.exe.config b/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.exe.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.pdb b/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.pdb new file mode 100644 index 0000000..1805eeb Binary files /dev/null and b/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.pdb differ diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.vshost.exe b/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.vshost.exe new file mode 100644 index 0000000..212bd7f Binary files /dev/null and b/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.vshost.exe differ diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.vshost.exe.config b/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.vshost.exe.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/08 - Structs (Value Types)/Chapter 8 - Structs/bin/Debug/Chapter 8 - Structs.vshost.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.csproj.FileListAbsolute.txt b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..955c2b9 --- /dev/null +++ b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.csproj.FileListAbsolute.txt @@ -0,0 +1,6 @@ +d:\data\booknew\chapters\code\Chapter 8 - Structs\bin\Debug\Chapter 8 - Structs.exe.config +d:\data\booknew\chapters\code\Chapter 8 - Structs\obj\Debug\Chapter 8 - Structs.csprojResolveAssemblyReference.cache +d:\data\booknew\chapters\code\Chapter 8 - Structs\bin\Debug\Chapter 8 - Structs.exe +d:\data\booknew\chapters\code\Chapter 8 - Structs\bin\Debug\Chapter 8 - Structs.pdb +d:\data\booknew\chapters\code\Chapter 8 - Structs\obj\Debug\Chapter 8 - Structs.exe +d:\data\booknew\chapters\code\Chapter 8 - Structs\obj\Debug\Chapter 8 - Structs.pdb diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.csprojResolveAssemblyReference.cache b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.csprojResolveAssemblyReference.cache new file mode 100644 index 0000000..ff54045 Binary files /dev/null and b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.csprojResolveAssemblyReference.cache differ diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.exe b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.exe new file mode 100644 index 0000000..3fed961 Binary files /dev/null and b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.exe differ diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.pdb b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.pdb new file mode 100644 index 0000000..1805eeb Binary files /dev/null and b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/Chapter 8 - Structs.pdb differ diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..01ced6b Binary files /dev/null and b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs new file mode 100644 index 0000000..e69de29 diff --git a/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs b/08 - Structs (Value Types)/Chapter 8 - Structs/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs new file mode 100644 index 0000000..e69de29 diff --git a/08 - Structs (Value Types)/Structs and Constructors/Build1.bat b/08 - Structs (Value Types)/Structs and Constructors/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/08 - Structs (Value Types)/Structs and Constructors/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/08 - Structs (Value Types)/Structs and Constructors/File_1.cs b/08 - Structs (Value Types)/Structs and Constructors/File_1.cs new file mode 100644 index 0000000..b0d81a9 --- /dev/null +++ b/08 - Structs (Value Types)/Structs and Constructors/File_1.cs @@ -0,0 +1,26 @@ +// 09 - Structs (Value Types)\Structs and Constructors +// copyright 2000 Eric Gunnerson +using System; +struct Point +{ + int x; + int y; + + Point(int x, int y) + { + this.x = x; + this.y = y; + } + public override string ToString() + { + return(String.Format("({0}, {1})", x, y)); + } +} +class Test +{ + public static void Main() + { + Point[] points = new Point[5]; + Console.WriteLine("[2] = {0}", points[2]); + } +} \ No newline at end of file diff --git a/09 - Interfaces/A Simple Example/Build1.bat b/09 - Interfaces/A Simple Example/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/09 - Interfaces/A Simple Example/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/09 - Interfaces/A Simple Example/File_1.cs b/09 - Interfaces/A Simple Example/File_1.cs new file mode 100644 index 0000000..24e8000 --- /dev/null +++ b/09 - Interfaces/A Simple Example/File_1.cs @@ -0,0 +1,45 @@ +// 10 - Interfaces\A Simple Example +// copyright 2000 Eric Gunnerson +public class DiagramObject +{ + public DiagramObject() {} +} + +interface IScalable +{ + void ScaleX(float factor); + void ScaleY(float factor); +} +// A diagram object that also implements IScalable +public class TextObject: DiagramObject, IScalable +{ + public TextObject(string text) + { + this.text = text; + } + // implementing IScalable.ScaleX() + public void ScaleX(float factor) + { + // scale the object here. + } + + // implementing IScalable.ScaleY() + public void ScaleY(float factor) + { + // scale the object here. + } + + private string text; +} + +class Test +{ + public static void Main() + { + TextObject text = new TextObject("Hello"); + + IScalable scalable = (IScalable) text; + scalable.ScaleX(0.5F); + scalable.ScaleY(0.5F); + } +} \ No newline at end of file diff --git a/09 - Interfaces/Interfaces Based on Interfaces/Build1.bat b/09 - Interfaces/Interfaces Based on Interfaces/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/09 - Interfaces/Interfaces Based on Interfaces/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/09 - Interfaces/Interfaces Based on Interfaces/File_1.cs b/09 - Interfaces/Interfaces Based on Interfaces/File_1.cs new file mode 100644 index 0000000..10d9e3b --- /dev/null +++ b/09 - Interfaces/Interfaces Based on Interfaces/File_1.cs @@ -0,0 +1,9 @@ +// 10 - Interfaces\Interfaces Based on Interfaces +// copyright 2000 Eric Gunnerson +using System.Runtime.Serialization; +using System; +interface IComparableSerializable : +IComparable, ISerializable +{ + string GetStatusString(); +} \ No newline at end of file diff --git a/09 - Interfaces/Interfaces and Inheritance/Build1.bat b/09 - Interfaces/Interfaces and Inheritance/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/09 - Interfaces/Interfaces and Inheritance/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/09 - Interfaces/Interfaces and Inheritance/File_1.cs b/09 - Interfaces/Interfaces and Inheritance/File_1.cs new file mode 100644 index 0000000..30647dc --- /dev/null +++ b/09 - Interfaces/Interfaces and Inheritance/File_1.cs @@ -0,0 +1,33 @@ +// 10 - Interfaces\Interfaces and Inheritance +// copyright 2000 Eric Gunnerson +using System; +interface IHelper +{ + void HelpMeNow(); +} +public class Base: IHelper +{ + public void HelpMeNow() + { + Console.WriteLine("Base.HelpMeNow()"); + } +} +// Does not implement IHelper, though it has the right +// form. +public class Derived: Base +{ + public new void HelpMeNow() + { + Console.WriteLine("Derived.HelpMeNow()"); + } +} +class Test +{ + public static void Main() + { + Derived der = new Derived(); + der.HelpMeNow(); + IHelper helper = (IHelper) der; + helper.HelpMeNow(); + } +} \ No newline at end of file diff --git a/09 - Interfaces/Interfaces and Structs/Build1.bat b/09 - Interfaces/Interfaces and Structs/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/09 - Interfaces/Interfaces and Structs/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/09 - Interfaces/Interfaces and Structs/File_1.cs b/09 - Interfaces/Interfaces and Structs/File_1.cs new file mode 100644 index 0000000..e973600 --- /dev/null +++ b/09 - Interfaces/Interfaces and Structs/File_1.cs @@ -0,0 +1,33 @@ +// 10 - Interfaces\Interfaces and Structs +// copyright 2000 Eric Gunnerson +using System; +struct Number: IComparable +{ + int value; + + public Number(int value) + { + this.value = value; + } + public int CompareTo(object obj2) + { + Number num2 = (Number) obj2; + if (value < num2.value) + return(-1); + else if (value > num2.value) + return(1); + else + return(0); + } +} +class Test +{ + public static void Main() + { + Number x = new Number(33); + Number y = new Number(34); + + IComparable Ic = (IComparable) x; + Console.WriteLine("x compared to y = {0}", Ic.CompareTo(y)); + } +} \ No newline at end of file diff --git a/09 - Interfaces/Multiple Implementation/Build1.bat b/09 - Interfaces/Multiple Implementation/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/09 - Interfaces/Multiple Implementation/Build2.bat b/09 - Interfaces/Multiple Implementation/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/Build1.bat b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/Build3.bat b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/Build3.bat new file mode 100644 index 0000000..b764232 --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/Build3.bat @@ -0,0 +1 @@ +csc File_3.cs diff --git a/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/Build4.bat b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/Build4.bat new file mode 100644 index 0000000..8bc2ca0 --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/Build4.bat @@ -0,0 +1 @@ +csc File_4.cs diff --git a/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/File_1.cs b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/File_1.cs new file mode 100644 index 0000000..5a2842d --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/File_1.cs @@ -0,0 +1,38 @@ +// 10 - Interfaces\Multiple Implementation\Explicit Interface Implementation +// copyright 2000 Eric Gunnerson +using System; +interface IFoo +{ + void Execute(); +} + +interface IBar +{ + void Execute(); +} + +class Tester: IFoo, IBar +{ + void IFoo.Execute() + { + Console.WriteLine("IFoo.Execute implementation"); + } + void IBar.Execute() + { + Console.WriteLine("IBar.Execute implementation"); + } +} + +class Test +{ + public static void Main() + { + Tester tester = new Tester(); + + IFoo iFoo = (IFoo) tester; + iFoo.Execute(); + + IBar iBar = (IBar) tester; + iBar.Execute(); + } +} \ No newline at end of file diff --git a/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/File_3.cs b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/File_3.cs new file mode 100644 index 0000000..e8bb7c7 --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/File_3.cs @@ -0,0 +1,34 @@ +// 10 - Interfaces\Multiple Implementation\Explicit Interface Implementation +// copyright 2000 Eric Gunnerson +// error +using System; +interface IFoo +{ + void Execute(); +} + +interface IBar +{ + void Execute(); +} + +class Tester: IFoo, IBar +{ + void IFoo.Execute() + { + Console.WriteLine("IFoo.Execute implementation"); + } + void IBar.Execute() + { + Console.WriteLine("IBar.Execute implementation"); + } +} +class Test +{ + public static void Main() + { + Tester tester = new Tester(); + + tester.Execute(); + } +} \ No newline at end of file diff --git a/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/File_4.cs b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/File_4.cs new file mode 100644 index 0000000..6eaf11a --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/Explicit Interface Implementation/File_4.cs @@ -0,0 +1,37 @@ +// 10 - Interfaces\Multiple Implementation\Explicit Interface Implementation +// copyright 2000 Eric Gunnerson +using System; +interface IFoo +{ + void Execute(); +} + +interface IBar +{ + void Execute(); +} +class Tester: IFoo, IBar +{ + void IFoo.Execute() + { + Console.WriteLine("IFoo.Execute implementation"); + } + void IBar.Execute() + { + Console.WriteLine("IBar.Execute implementation"); + } + + public void Execute() + { + ((IFoo) this).Execute(); + } +} +class Test +{ + public static void Main() + { + Tester tester = new Tester(); + + tester.Execute(); + } +} \ No newline at end of file diff --git a/09 - Interfaces/Multiple Implementation/File_1.cs b/09 - Interfaces/Multiple Implementation/File_1.cs new file mode 100644 index 0000000..d1f73d6 --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/File_1.cs @@ -0,0 +1,17 @@ +// 10 - Interfaces\Multiple Implementation +// copyright 2000 Eric Gunnerson +interface IFoo +{ + void ExecuteFoo(); +} + +interface IBar +{ + void ExecuteBar(); +} + +class Tester: IFoo, IBar +{ + public void ExecuteFoo() {} + public void ExecuteBar() {} +} \ No newline at end of file diff --git a/09 - Interfaces/Multiple Implementation/File_2.cs b/09 - Interfaces/Multiple Implementation/File_2.cs new file mode 100644 index 0000000..cf9394e --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/File_2.cs @@ -0,0 +1,18 @@ +// 10 - Interfaces\Multiple Implementation +// copyright 2000 Eric Gunnerson +// error +interface IFoo +{ + void Execute(); +} + +interface IBar +{ + void Execute(); +} + +class Tester: IFoo, IBar +{ + // IFoo or IBar implementation? + public void Execute() {} +} \ No newline at end of file diff --git a/09 - Interfaces/Multiple Implementation/Implementation Hiding/Build1.bat b/09 - Interfaces/Multiple Implementation/Implementation Hiding/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/Implementation Hiding/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/09 - Interfaces/Multiple Implementation/Implementation Hiding/File_1.cs b/09 - Interfaces/Multiple Implementation/Implementation Hiding/File_1.cs new file mode 100644 index 0000000..7b4a2f3 --- /dev/null +++ b/09 - Interfaces/Multiple Implementation/Implementation Hiding/File_1.cs @@ -0,0 +1,33 @@ +// 10 - Interfaces\Multiple Implementation\Implementation Hiding +// copyright 2000 Eric Gunnerson +using System; +class DrawingSurface +{ + +} +interface IRenderIcon +{ + void DrawIcon(DrawingSurface surface, int x, int y); + void DragIcon(DrawingSurface surface, int x, int y, int x2, int y2); + void ResizeIcon(DrawingSurface surface, int xsize, int ysize); +} +class Employee: IRenderIcon +{ + public Employee(int id, string name) + { + this.id = id; + this.name = name; + } + void IRenderIcon.DrawIcon(DrawingSurface surface, int x, int y) + { + } + void IRenderIcon.DragIcon(DrawingSurface surface, int x, int y, + int x2, int y2) + { + } + void IRenderIcon.ResizeIcon(DrawingSurface surface, int xsize, int ysize) + { + } + int id; + string name; +} \ No newline at end of file diff --git a/09 - Interfaces/The As Operator/Build1.bat b/09 - Interfaces/The As Operator/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/09 - Interfaces/The As Operator/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/09 - Interfaces/The As Operator/File_1.cs b/09 - Interfaces/The As Operator/File_1.cs new file mode 100644 index 0000000..90238ce --- /dev/null +++ b/09 - Interfaces/The As Operator/File_1.cs @@ -0,0 +1,59 @@ +// 10 - Interfaces\The As Operator +// copyright 2000 Eric Gunnerson +using System; +interface IScalable +{ + void ScaleX(float factor); + void ScaleY(float factor); +} +public class DiagramObject +{ + public DiagramObject() {} +} +public class TextObject: DiagramObject, IScalable +{ + public TextObject(string text) + { + this.text = text; + } + // implementing IScalable.ScaleX() + public void ScaleX(float factor) + { + Console.WriteLine("ScaleX: {0} {1}", text, factor); + // scale the object here. + } + + // implementing IScalable.ScaleY() + public void ScaleY(float factor) + { + Console.WriteLine("ScaleY: {0} {1}", text, factor); + // scale the object here. + } + + private string text; +} +class Test +{ + public static void Main() + { + DiagramObject[] dArray = new DiagramObject[100]; + + dArray[0] = new DiagramObject(); + dArray[1] = new TextObject("Text Dude"); + dArray[2] = new TextObject("Text Backup"); + + // array gets initialized here, with classes that + // derive from DiagramObject. Some of them implement + // IScalable. + + foreach (DiagramObject d in dArray) + { + IScalable scalable = d as IScalable; + if (scalable != null) + { + scalable.ScaleX(0.1F); + scalable.ScaleY(10.0F); + } + } + } +} \ No newline at end of file diff --git a/09 - Interfaces/Working with Interfaces/Build1.bat b/09 - Interfaces/Working with Interfaces/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/09 - Interfaces/Working with Interfaces/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/09 - Interfaces/Working with Interfaces/File_1.cs b/09 - Interfaces/Working with Interfaces/File_1.cs new file mode 100644 index 0000000..d12794a --- /dev/null +++ b/09 - Interfaces/Working with Interfaces/File_1.cs @@ -0,0 +1,59 @@ +// 10 - Interfaces\Working with Interfaces +// copyright 2000 Eric Gunnerson +using System; +interface IScalable +{ + void ScaleX(float factor); + void ScaleY(float factor); +} +public class DiagramObject +{ + public DiagramObject() {} +} +public class TextObject: DiagramObject, IScalable +{ + public TextObject(string text) + { + this.text = text; + } + // implementing IScalable.ScaleX() + public void ScaleX(float factor) + { + Console.WriteLine("ScaleX: {0} {1}", text, factor); + // scale the object here. + } + + // implementing IScalable.ScaleY() + public void ScaleY(float factor) + { + Console.WriteLine("ScaleY: {0} {1}", text, factor); + // scale the object here. + } + + private string text; +} +class Test +{ + public static void Main() + { + DiagramObject[] dArray = new DiagramObject[100]; + + dArray[0] = new DiagramObject(); + dArray[1] = new TextObject("Text Dude"); + dArray[2] = new TextObject("Text Backup"); + + // array gets initialized here, with classes that + // derive from DiagramObject. Some of them implement + // IScalable. + + foreach (DiagramObject d in dArray) + { + if (d is IScalable) + { + IScalable scalable = (IScalable) d; + scalable.ScaleX(0.1F); + scalable.ScaleY(10.0F); + } + } + } +} \ No newline at end of file diff --git a/10 - Versioning and Aliases/A Versioning Example/Build1.bat b/10 - Versioning and Aliases/A Versioning Example/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/10 - Versioning and Aliases/A Versioning Example/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/10 - Versioning and Aliases/A Versioning Example/Build2.bat b/10 - Versioning and Aliases/A Versioning Example/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/10 - Versioning and Aliases/A Versioning Example/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/10 - Versioning and Aliases/A Versioning Example/Build3.bat b/10 - Versioning and Aliases/A Versioning Example/Build3.bat new file mode 100644 index 0000000..b764232 --- /dev/null +++ b/10 - Versioning and Aliases/A Versioning Example/Build3.bat @@ -0,0 +1 @@ +csc File_3.cs diff --git a/10 - Versioning and Aliases/A Versioning Example/Build4.bat b/10 - Versioning and Aliases/A Versioning Example/Build4.bat new file mode 100644 index 0000000..8bc2ca0 --- /dev/null +++ b/10 - Versioning and Aliases/A Versioning Example/Build4.bat @@ -0,0 +1 @@ +csc File_4.cs diff --git a/10 - Versioning and Aliases/A Versioning Example/Build5.bat b/10 - Versioning and Aliases/A Versioning Example/Build5.bat new file mode 100644 index 0000000..3d4a61f --- /dev/null +++ b/10 - Versioning and Aliases/A Versioning Example/Build5.bat @@ -0,0 +1 @@ +csc File_5.cs diff --git a/10 - Versioning and Aliases/A Versioning Example/File_1.cs b/10 - Versioning and Aliases/A Versioning Example/File_1.cs new file mode 100644 index 0000000..5bb9a9b --- /dev/null +++ b/10 - Versioning and Aliases/A Versioning Example/File_1.cs @@ -0,0 +1,8 @@ +// 11 - Versioning\A Versioning Example +// copyright 2000 Eric Gunnerson +public class Control +{ +} +public class MyControl: Control +{ +} \ No newline at end of file diff --git a/10 - Versioning and Aliases/A Versioning Example/File_2.cs b/10 - Versioning and Aliases/A Versioning Example/File_2.cs new file mode 100644 index 0000000..f97a722 --- /dev/null +++ b/10 - Versioning and Aliases/A Versioning Example/File_2.cs @@ -0,0 +1,10 @@ +// 11 - Versioning\A Versioning Example +// copyright 2000 Eric Gunnerson +public class Control +{ + +} +public class MyControl: Control +{ + public virtual void Foo() {} +} \ No newline at end of file diff --git a/10 - Versioning and Aliases/A Versioning Example/File_3.cs b/10 - Versioning and Aliases/A Versioning Example/File_3.cs new file mode 100644 index 0000000..4ddd091 --- /dev/null +++ b/10 - Versioning and Aliases/A Versioning Example/File_3.cs @@ -0,0 +1,11 @@ +// 11 - Versioning\A Versioning Example +// copyright 2000 Eric Gunnerson +public class Control +{ + // newly added virtual + public virtual void Foo() {} +} +public class MyControl: Control +{ + public virtual void Foo() {} +} \ No newline at end of file diff --git a/10 - Versioning and Aliases/A Versioning Example/File_4.cs b/10 - Versioning and Aliases/A Versioning Example/File_4.cs new file mode 100644 index 0000000..0fcff90 --- /dev/null +++ b/10 - Versioning and Aliases/A Versioning Example/File_4.cs @@ -0,0 +1,11 @@ +// 11 - Versioning\A Versioning Example +// copyright 2000 Eric Gunnerson +class Control +{ + public virtual void Foo() {} +} +class MyControl: Control +{ + // not an override + public new virtual void Foo() {} +} \ No newline at end of file diff --git a/10 - Versioning and Aliases/A Versioning Example/File_5.cs b/10 - Versioning and Aliases/A Versioning Example/File_5.cs new file mode 100644 index 0000000..175f733 --- /dev/null +++ b/10 - Versioning and Aliases/A Versioning Example/File_5.cs @@ -0,0 +1,11 @@ +// 11 - Versioning\A Versioning Example +// copyright 2000 Eric Gunnerson +class Control +{ + public virtual void Foo() {} +} +class MyControl: Control +{ + // an override for Control.Foo() + public override void Foo() {} +} \ No newline at end of file diff --git a/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.csproj b/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.csproj new file mode 100644 index 0000000..42bee33 --- /dev/null +++ b/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.csproj @@ -0,0 +1,61 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {2FDCD8A1-F856-489F-ADEC-555344F2324E} + Exe + Properties + Chapter_10_Versioning + Chapter 10 Versioning + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + Fred + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.csproj.user b/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.csproj.user new file mode 100644 index 0000000..ace9a86 --- /dev/null +++ b/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.csproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.sln b/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.sln new file mode 100644 index 0000000..226ad4e --- /dev/null +++ b/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C# Express 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chapter 10 Versioning", "Chapter 10 Versioning.csproj", "{2FDCD8A1-F856-489F-ADEC-555344F2324E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2FDCD8A1-F856-489F-ADEC-555344F2324E}.Debug|x86.ActiveCfg = Debug|x86 + {2FDCD8A1-F856-489F-ADEC-555344F2324E}.Debug|x86.Build.0 = Debug|x86 + {2FDCD8A1-F856-489F-ADEC-555344F2324E}.Release|x86.ActiveCfg = Release|x86 + {2FDCD8A1-F856-489F-ADEC-555344F2324E}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.suo b/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.suo new file mode 100644 index 0000000..6e1545f Binary files /dev/null and b/10 - Versioning and Aliases/Chapter 10 Versioning/Chapter 10 Versioning.suo differ diff --git a/10 - Versioning and Aliases/Chapter 10 Versioning/Employee1.cs b/10 - Versioning and Aliases/Chapter 10 Versioning/Employee1.cs new file mode 100644 index 0000000..251dad6 --- /dev/null +++ b/10 - Versioning and Aliases/Chapter 10 Versioning/Employee1.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MyCompany.HumanResources.Application.DataModel +{ + class Employee + { + public string Name { get; set; } + } +} diff --git a/10 - Versioning and Aliases/Chapter 10 Versioning/Employee2.cs b/10 - Versioning and Aliases/Chapter 10 Versioning/Employee2.cs new file mode 100644 index 0000000..24f22df --- /dev/null +++ b/10 - Versioning and Aliases/Chapter 10 Versioning/Employee2.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MyCompany.Computer.Network.Model.Classes +{ + class Employee + { + public string Name { get; set; } + } +} diff --git a/10 - Versioning and Aliases/Chapter 10 Versioning/Program.cs b/10 - Versioning and Aliases/Chapter 10 Versioning/Program.cs new file mode 100644 index 0000000..72d7830 --- /dev/null +++ b/10 - Versioning and Aliases/Chapter 10 Versioning/Program.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +using NetworkEmployee = MyCompany.Computer.Network.Model.Classes.Employee; +using HREmployee = MyCompany.HumanResources.Application.DataModel.Employee; + +namespace Chapter_10_Versioning +{ + class Program + { + static void Main(string[] args) + { + + } + +public MyCompany.Computer.Network.Model.Classes.Employee CopyEmployeeData2(MyCompany.HumanResources.Application.DataModel.Employee hrEmployee) +{ + MyCompany.Computer.Network.Model.Classes.Employee networkEmployee = new MyCompany.Computer.Network.Model.Classes.Employee(); + networkEmployee.Name = hrEmployee.Name; + + return networkEmployee; +} + +public NetworkEmployee CopyEmployeeData(HREmployee hrEmployee) +{ + NetworkEmployee networkEmployee = new NetworkEmployee(); + networkEmployee.Name = hrEmployee.Name; + + return networkEmployee; +} + + } +} diff --git a/10 - Versioning and Aliases/Chapter 10 Versioning/Properties/AssemblyInfo.cs b/10 - Versioning and Aliases/Chapter 10 Versioning/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..750ead3 --- /dev/null +++ b/10 - Versioning and Aliases/Chapter 10 Versioning/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Chapter 10 Versioning")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Chapter 10 Versioning")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a8ed280a-ba1b-4930-a010-127d3a1cdcad")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/10 - Versioning and Aliases/Chapter 10 Versioning/bin/Debug/Chapter 10 Versioning.vshost.exe b/10 - Versioning and Aliases/Chapter 10 Versioning/bin/Debug/Chapter 10 Versioning.vshost.exe new file mode 100644 index 0000000..bb84a51 Binary files /dev/null and b/10 - Versioning and Aliases/Chapter 10 Versioning/bin/Debug/Chapter 10 Versioning.vshost.exe differ diff --git a/10 - Versioning and Aliases/Chapter 10 Versioning/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/10 - Versioning and Aliases/Chapter 10 Versioning/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..32eca11 Binary files /dev/null and b/10 - Versioning and Aliases/Chapter 10 Versioning/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/10 - Versioning and Aliases/Chapter 10 Versioning/obj/x86/Debug/build.force b/10 - Versioning and Aliases/Chapter 10 Versioning/obj/x86/Debug/build.force new file mode 100644 index 0000000..e69de29 diff --git a/10 - Versioning and Aliases/ExternAlias/MyApp.exe b/10 - Versioning and Aliases/ExternAlias/MyApp.exe new file mode 100644 index 0000000..651df29 Binary files /dev/null and b/10 - Versioning and Aliases/ExternAlias/MyApp.exe differ diff --git a/10 - Versioning and Aliases/ExternAlias/math.cs b/10 - Versioning and Aliases/ExternAlias/math.cs new file mode 100644 index 0000000..ee1a2a8 --- /dev/null +++ b/10 - Versioning and Aliases/ExternAlias/math.cs @@ -0,0 +1,8 @@ +//in assembly Math.dll +namespace AcmeScientific +{ + public class Math + { + public int Calc() { return 0;} + } +} diff --git a/10 - Versioning and Aliases/ExternAlias/maths.dll b/10 - Versioning and Aliases/ExternAlias/maths.dll new file mode 100644 index 0000000..78a750e Binary files /dev/null and b/10 - Versioning and Aliases/ExternAlias/maths.dll differ diff --git a/10 - Versioning and Aliases/ExternAlias/source.cs b/10 - Versioning and Aliases/ExternAlias/source.cs new file mode 100644 index 0000000..5cef490 --- /dev/null +++ b/10 - Versioning and Aliases/ExternAlias/source.cs @@ -0,0 +1,16 @@ +extern alias Maths; +extern alias Utils; + +namespace AcmeScientific.MyApp +{ +class App{ + static void Main() + { + Maths::AcmeScientific.Math m = new Maths::AcmeScientific.Math(); + m.Calc(); + + Utils::AcmeScientific.Math u = new Utils::AcmeScientific.Math(); + u.DoSums(); + } + } +} \ No newline at end of file diff --git a/10 - Versioning and Aliases/ExternAlias/source1.cs b/10 - Versioning and Aliases/ExternAlias/source1.cs new file mode 100644 index 0000000..6ee16fc --- /dev/null +++ b/10 - Versioning and Aliases/ExternAlias/source1.cs @@ -0,0 +1,13 @@ +extern alias Maths; +using Maths::AcmeScientific; + +namespace AcmeScientific.MyApp +{ +class App{ + static void Main() + { + Math m = new Math(); + m.Calc(); + } + } +} \ No newline at end of file diff --git a/10 - Versioning and Aliases/ExternAlias/source2.cs b/10 - Versioning and Aliases/ExternAlias/source2.cs new file mode 100644 index 0000000..8145f69 --- /dev/null +++ b/10 - Versioning and Aliases/ExternAlias/source2.cs @@ -0,0 +1,12 @@ +using AcmeScientific; + +namespace AcmeScientific.MyApp +{ +class App{ + static void Main() + { + Math m = new Math(); + m.Calc(); + } + } +} \ No newline at end of file diff --git a/10 - Versioning and Aliases/ExternAlias/source3.cs b/10 - Versioning and Aliases/ExternAlias/source3.cs new file mode 100644 index 0000000..970127a --- /dev/null +++ b/10 - Versioning and Aliases/ExternAlias/source3.cs @@ -0,0 +1,12 @@ +using global::AcmeScientific; + +namespace AcmeScientific.MyApp +{ +class App{ + static void Main() + { + Math m = new Math(); + m.Calc(); + } + } +} \ No newline at end of file diff --git a/10 - Versioning and Aliases/ExternAlias/utils.cs b/10 - Versioning and Aliases/ExternAlias/utils.cs new file mode 100644 index 0000000..fffad7d --- /dev/null +++ b/10 - Versioning and Aliases/ExternAlias/utils.cs @@ -0,0 +1,8 @@ +//in assembly Utils.dll +namespace AcmeScientific +{ + public class Math + { + public void DoSums() {} + } +} \ No newline at end of file diff --git a/10 - Versioning and Aliases/ExternAlias/utils.dll b/10 - Versioning and Aliases/ExternAlias/utils.dll new file mode 100644 index 0000000..1b7ee3a Binary files /dev/null and b/10 - Versioning and Aliases/ExternAlias/utils.dll differ diff --git a/11 - Statements and Flow of Execution/Iteration Statements/Do/Build1.bat b/11 - Statements and Flow of Execution/Iteration Statements/Do/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/Do/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/11 - Statements and Flow of Execution/Iteration Statements/Do/File_1.cs b/11 - Statements and Flow of Execution/Iteration Statements/Do/File_1.cs new file mode 100644 index 0000000..3423b6f --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/Do/File_1.cs @@ -0,0 +1,15 @@ +// 12 - Statements and Flow of Execution\Iteration Statements\Do +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + int n = 0; + do + { + Console.WriteLine("Number is {0}", n); + n++; + } while (n < 10); + } +} \ No newline at end of file diff --git a/11 - Statements and Flow of Execution/Iteration Statements/For/Build1.bat b/11 - Statements and Flow of Execution/Iteration Statements/For/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/For/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/11 - Statements and Flow of Execution/Iteration Statements/For/Build2.bat b/11 - Statements and Flow of Execution/Iteration Statements/For/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/For/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/11 - Statements and Flow of Execution/Iteration Statements/For/File_1.cs b/11 - Statements and Flow of Execution/Iteration Statements/For/File_1.cs new file mode 100644 index 0000000..b4c70bf --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/For/File_1.cs @@ -0,0 +1,11 @@ +// 12 - Statements and Flow of Execution\Iteration Statements\For +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + for (int n = 0; n < 10; n++) + Console.WriteLine("Number is {0}", n); + } +} \ No newline at end of file diff --git a/11 - Statements and Flow of Execution/Iteration Statements/For/File_2.cs b/11 - Statements and Flow of Execution/Iteration Statements/For/File_2.cs new file mode 100644 index 0000000..faedd1b --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/For/File_2.cs @@ -0,0 +1,18 @@ +// 12 - Statements and Flow of Execution\Iteration Statements\For +// copyright 2000 Eric Gunnerson +// error +using System; +class Test +{ + public static void Main() + { + for (int n = 0; n < 10; n++) + { + if (n == 8) + break; + Console.WriteLine("Number is {0}", n); + } + // error; n is out of scope + Console.WriteLine("Last Number is {0}", n); + } +} \ No newline at end of file diff --git a/11 - Statements and Flow of Execution/Iteration Statements/Foreach/Build1.bat b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/11 - Statements and Flow of Execution/Iteration Statements/Foreach/Build2.bat b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/11 - Statements and Flow of Execution/Iteration Statements/Foreach/Build3.bat b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/Build3.bat new file mode 100644 index 0000000..b764232 --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/Build3.bat @@ -0,0 +1 @@ +csc File_3.cs diff --git a/11 - Statements and Flow of Execution/Iteration Statements/Foreach/File_1.cs b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/File_1.cs new file mode 100644 index 0000000..73bbf90 --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/File_1.cs @@ -0,0 +1,20 @@ +// 12 - Statements and Flow of Execution\Iteration Statements\Foreach +// copyright 2000 Eric Gunnerson +using System; +using System.Collections; +class MyObject +{ +} +class Test +{ + public static void Process(ArrayList arr) + { + for (int nIndex = 0; nIndex < arr.Count; nIndex++) + { + // cast is required by ArrayList stores + // object references + MyObject current = (MyObject) arr[nIndex]; + Console.WriteLine("Item: {0}", current); + } + } +} \ No newline at end of file diff --git a/11 - Statements and Flow of Execution/Iteration Statements/Foreach/File_2.cs b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/File_2.cs new file mode 100644 index 0000000..89ec8ac --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/File_2.cs @@ -0,0 +1,17 @@ +// 12 - Statements and Flow of Execution\Iteration Statements\Foreach +// copyright 2000 Eric Gunnerson +using System; +using System.Collections; +class MyObject +{ +} +class Test +{ + public static void Process(ArrayList arr) + { + foreach (MyObject current in arr) + { + Console.WriteLine("Item: {0}", current); + } + } +} \ No newline at end of file diff --git a/11 - Statements and Flow of Execution/Iteration Statements/Foreach/File_3.cs b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/File_3.cs new file mode 100644 index 0000000..229096f --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/Foreach/File_3.cs @@ -0,0 +1,21 @@ +// 12 - Statements and Flow of Execution\Iteration Statements\Foreach +// copyright 2000 Eric Gunnerson +using System; +using System.Collections; +class Test +{ + public static void Main() + { + Hashtable hash = new Hashtable(); + hash.Add("Fred", "Flintstone"); + hash.Add("Barney", "Rubble"); + hash.Add("Mr.", "Slate"); + hash.Add("Wilma", "Flintstone"); + hash.Add("Betty", "Rubble"); + + foreach (string firstName in hash.Keys) + { + Console.WriteLine("{0} {1}", firstName, hash[firstName]); + } + } +} \ No newline at end of file diff --git a/11 - Statements and Flow of Execution/Iteration Statements/While/Build1.bat b/11 - Statements and Flow of Execution/Iteration Statements/While/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/While/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/11 - Statements and Flow of Execution/Iteration Statements/While/Build2.bat b/11 - Statements and Flow of Execution/Iteration Statements/While/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/While/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/11 - Statements and Flow of Execution/Iteration Statements/While/File_1.cs b/11 - Statements and Flow of Execution/Iteration Statements/While/File_1.cs new file mode 100644 index 0000000..31215b2 --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/While/File_1.cs @@ -0,0 +1,15 @@ +// 12 - Statements and Flow of Execution\Iteration Statements\While +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + int n = 0; + while (n < 10) + { + Console.WriteLine("Number is {0}", n); + n++; + } + } +} \ No newline at end of file diff --git a/11 - Statements and Flow of Execution/Iteration Statements/While/File_2.cs b/11 - Statements and Flow of Execution/Iteration Statements/While/File_2.cs new file mode 100644 index 0000000..297907c --- /dev/null +++ b/11 - Statements and Flow of Execution/Iteration Statements/While/File_2.cs @@ -0,0 +1,22 @@ +// 12 - Statements and Flow of Execution\Iteration Statements\While +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + int n = 0; + while (n < 10) + { + if (n == 3) + { + n++; + continue; + } + if (n == 8) + break; + Console.WriteLine("Number is {0}", n); + n++; + } + } +} \ No newline at end of file diff --git a/11 - Statements and Flow of Execution/Selection Statements/If/Build1.bat b/11 - Statements and Flow of Execution/Selection Statements/If/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/11 - Statements and Flow of Execution/Selection Statements/If/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/11 - Statements and Flow of Execution/Selection Statements/If/File_1.cs b/11 - Statements and Flow of Execution/Selection Statements/If/File_1.cs new file mode 100644 index 0000000..c4a6a5f --- /dev/null +++ b/11 - Statements and Flow of Execution/Selection Statements/If/File_1.cs @@ -0,0 +1,17 @@ +// 12 - Statements and Flow of Execution\Selection Statements\If +// copyright 2000 Eric Gunnerson +// error +using System; +class Test +{ + public static void Main() + { + int value; + + if (value) // invalid + System.Console.WriteLine("true"); + + if (value == 0) // must use this + System.Console.WriteLine("true"); + } +} \ No newline at end of file diff --git a/11 - Statements and Flow of Execution/Selection Statements/Switch/Build1.bat b/11 - Statements and Flow of Execution/Selection Statements/Switch/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/11 - Statements and Flow of Execution/Selection Statements/Switch/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/11 - Statements and Flow of Execution/Selection Statements/Switch/Build2.bat b/11 - Statements and Flow of Execution/Selection Statements/Switch/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/11 - Statements and Flow of Execution/Selection Statements/Switch/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/11 - Statements and Flow of Execution/Selection Statements/Switch/File_1.cs b/11 - Statements and Flow of Execution/Selection Statements/Switch/File_1.cs new file mode 100644 index 0000000..db2700c --- /dev/null +++ b/11 - Statements and Flow of Execution/Selection Statements/Switch/File_1.cs @@ -0,0 +1,29 @@ +// 12 - Statements and Flow of Execution\Selection Statements\Switch +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public void Process(int i) + { + switch (i) + { + case 1: + case 2: + // code here handles both 1 and 2 + Console.WriteLine("Low Number"); + break; + + case 3: + Console.WriteLine("3"); + goto case 4; + + case 4: + Console.WriteLine("Middle Number"); + break; + + default: + Console.WriteLine("Default Number"); + break; + } + } +} \ No newline at end of file diff --git a/11 - Statements and Flow of Execution/Selection Statements/Switch/File_2.cs b/11 - Statements and Flow of Execution/Selection Statements/Switch/File_2.cs new file mode 100644 index 0000000..54b485e --- /dev/null +++ b/11 - Statements and Flow of Execution/Selection Statements/Switch/File_2.cs @@ -0,0 +1,24 @@ +// 12 - Statements and Flow of Execution\Selection Statements\Switch +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public void Process(string htmlTag) + { + switch (htmlTag) + { + case "P": + Console.WriteLine("Paragraph start"); + break; + case "DIV": + Console.WriteLine("Division"); + break; + case "FORM": + Console.WriteLine("Form Tag"); + break; + default: + Console.WriteLine("Unrecognized tag"); + break; + } + } +} \ No newline at end of file diff --git a/12 - Variable Scoping and Definite Assignment/Build.bat b/12 - Variable Scoping and Definite Assignment/Build.bat new file mode 100644 index 0000000..6b55348 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Build.bat @@ -0,0 +1 @@ +csc File_.cs diff --git a/12 - Variable Scoping and Definite Assignment/Build1.bat b/12 - Variable Scoping and Definite Assignment/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/App.config b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/App.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment.csproj b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment.csproj new file mode 100644 index 0000000..0ba1189 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {DECF55EC-60F3-4F63-AB44-ED1695CA59ED} + Exe + Properties + Chapter_12___Variable_Scoping_and_Definite_Assignment + Chapter 12 - Variable Scoping and Definite Assignment + v4.5 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment.sln b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment.sln new file mode 100644 index 0000000..0c82d50 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chapter 12 - Variable Scoping and Definite Assignment", "Chapter 12 - Variable Scoping and Definite Assignment.csproj", "{DECF55EC-60F3-4F63-AB44-ED1695CA59ED}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DECF55EC-60F3-4F63-AB44-ED1695CA59ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DECF55EC-60F3-4F63-AB44-ED1695CA59ED}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DECF55EC-60F3-4F63-AB44-ED1695CA59ED}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DECF55EC-60F3-4F63-AB44-ED1695CA59ED}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment.v11.suo b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment.v11.suo new file mode 100644 index 0000000..e90712a Binary files /dev/null and b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment.v11.suo differ diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/ClassDefiniteAssignment.cs b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/ClassDefiniteAssignment.cs new file mode 100644 index 0000000..26ae965 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/ClassDefiniteAssignment.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chapter_12___Variable_Scoping_and_Definite_Assignment +{ +class AlwaysNullName +{ + string m_name; + + string GetName() + { + return m_name; + } +} +} diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/MyClass.cs b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/MyClass.cs new file mode 100644 index 0000000..30c804f --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/MyClass.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chapter_12___Variable_Scoping_and_Definite_Assignment +{ + class MyClass + { + public MyClass(int value) + { + m_value = value; + } + public int Calculate() + { + return (m_value * 10); + } + public int m_value; + } + class Test + { + public static void Mainly() + { + MyClass mine; + + //Console.WriteLine("{0}", mine.m_value); // error + //Console.WriteLine("{0}", mine.Calculate()); // error + mine = new MyClass(12); + Console.WriteLine("{0}", mine.m_value); // okay now… + } + } + +} diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/MyObject.cs b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/MyObject.cs new file mode 100644 index 0000000..213df67 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/MyObject.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chapter_12___Variable_Scoping_and_Definite_Assignment +{ + class MyObject + { + public MyObject(int x) + { + this.x = x; + } + int x; + } +} diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Program.cs b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Program.cs new file mode 100644 index 0000000..0f0a0da --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Program.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Chapter_12___Variable_Scoping_and_Definite_Assignment +{ + class Program + { + static void Main(string[] args) + { + } + } +} diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Properties/AssemblyInfo.cs b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e1bea46 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Chapter 12 - Variable Scoping and Definite Assignment")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Chapter 12 - Variable Scoping and Definite Assignment")] +[assembly: AssemblyCopyright("Copyright © 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5146d7c4-0ae1-495c-846e-0f036275d2c3")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.exe b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.exe new file mode 100644 index 0000000..b2efc5d Binary files /dev/null and b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.exe differ diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.exe.config b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.exe.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.pdb b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.pdb new file mode 100644 index 0000000..130370f Binary files /dev/null and b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.pdb differ diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.vshost.exe b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.vshost.exe new file mode 100644 index 0000000..212bd7f Binary files /dev/null and b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.vshost.exe differ diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.vshost.exe.config b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.vshost.exe.config new file mode 100644 index 0000000..8e15646 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/bin/Debug/Chapter 12 - Variable Scoping and Definite Assignment.vshost.exe.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.csproj.FileListAbsolute.txt b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..6b1f2b8 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.csproj.FileListAbsolute.txt @@ -0,0 +1,6 @@ +d:\data\booknew\chapters\code\Chapter 12 - Variable Scoping and Definite Assignment\bin\Debug\Chapter 12 - Variable Scoping and Definite Assignment.exe.config +d:\data\booknew\chapters\code\Chapter 12 - Variable Scoping and Definite Assignment\obj\Debug\Chapter 12 - Variable Scoping and Definite Assignment.csprojResolveAssemblyReference.cache +d:\data\booknew\chapters\code\Chapter 12 - Variable Scoping and Definite Assignment\bin\Debug\Chapter 12 - Variable Scoping and Definite Assignment.exe +d:\data\booknew\chapters\code\Chapter 12 - Variable Scoping and Definite Assignment\bin\Debug\Chapter 12 - Variable Scoping and Definite Assignment.pdb +d:\data\booknew\chapters\code\Chapter 12 - Variable Scoping and Definite Assignment\obj\Debug\Chapter 12 - Variable Scoping and Definite Assignment.exe +d:\data\booknew\chapters\code\Chapter 12 - Variable Scoping and Definite Assignment\obj\Debug\Chapter 12 - Variable Scoping and Definite Assignment.pdb diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.csprojResolveAssemblyReference.cache b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.csprojResolveAssemblyReference.cache new file mode 100644 index 0000000..ff54045 Binary files /dev/null and b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.csprojResolveAssemblyReference.cache differ diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.exe b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.exe new file mode 100644 index 0000000..b2efc5d Binary files /dev/null and b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.exe differ diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.pdb b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.pdb new file mode 100644 index 0000000..130370f Binary files /dev/null and b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/Chapter 12 - Variable Scoping and Definite Assignment.pdb differ diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..a0a7756 Binary files /dev/null and b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs new file mode 100644 index 0000000..e69de29 diff --git a/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs b/12 - Variable Scoping and Definite Assignment/Chapter 12 - Variable Scoping and Definite Assignment/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs new file mode 100644 index 0000000..e69de29 diff --git a/12 - Variable Scoping and Definite Assignment/Definite Assignment/Build1.bat b/12 - Variable Scoping and Definite Assignment/Definite Assignment/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Definite Assignment/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/12 - Variable Scoping and Definite Assignment/Definite Assignment/Build2.bat b/12 - Variable Scoping and Definite Assignment/Definite Assignment/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Definite Assignment/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/12 - Variable Scoping and Definite Assignment/Definite Assignment/Build3.bat b/12 - Variable Scoping and Definite Assignment/Definite Assignment/Build3.bat new file mode 100644 index 0000000..b764232 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Definite Assignment/Build3.bat @@ -0,0 +1 @@ +csc File_3.cs diff --git a/12 - Variable Scoping and Definite Assignment/Definite Assignment/Definite Assignment and Arrays/Build1.bat b/12 - Variable Scoping and Definite Assignment/Definite Assignment/Definite Assignment and Arrays/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Definite Assignment/Definite Assignment and Arrays/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/12 - Variable Scoping and Definite Assignment/Definite Assignment/Definite Assignment and Arrays/File_1.cs b/12 - Variable Scoping and Definite Assignment/Definite Assignment/Definite Assignment and Arrays/File_1.cs new file mode 100644 index 0000000..94e69a3 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Definite Assignment/Definite Assignment and Arrays/File_1.cs @@ -0,0 +1,27 @@ +// 13 - Variable Scoping and Definite Assignment\Definite Assignment\Definite Assignment and Arrays +// copyright 2000 Eric Gunnerson +using System; +struct Complex +{ + public Complex(float real, float imaginary) + { + this.real = real; + this.imaginary = imaginary; + } + public override string ToString() + { + return(String.Format("({0}, {0})", real, imaginary)); + } + + public float real; + public float imaginary; +} + +class Test +{ + public static void Main() + { + Complex[] arr = new Complex[10]; + Console.WriteLine("Element 5: {0}", arr[5]); // legal + } +} \ No newline at end of file diff --git a/12 - Variable Scoping and Definite Assignment/Definite Assignment/File_1.cs b/12 - Variable Scoping and Definite Assignment/Definite Assignment/File_1.cs new file mode 100644 index 0000000..e49e2bc --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Definite Assignment/File_1.cs @@ -0,0 +1,12 @@ +// 13 - Variable Scoping and Definite Assignment\Definite Assignment +// copyright 2000 Eric Gunnerson +// error +using System; +class Test +{ + public static void Main() + { + int n; + Console.WriteLine("Value of n is {0}", n); + } +} \ No newline at end of file diff --git a/12 - Variable Scoping and Definite Assignment/Definite Assignment/File_2.cs b/12 - Variable Scoping and Definite Assignment/Definite Assignment/File_2.cs new file mode 100644 index 0000000..4351af1 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Definite Assignment/File_2.cs @@ -0,0 +1,28 @@ +// 13 - Variable Scoping and Definite Assignment\Definite Assignment +// copyright 2000 Eric Gunnerson +// error +using System; +class MyClass +{ + public MyClass(int value) + { + this.value = value; + } + public int Calculate() + { + return(value * 10); + } + public int value; +} +class Test +{ + public static void Main() + { + MyClass mine; + + Console.WriteLine("{0}", mine.value); // error + Console.WriteLine("{0}", mine.Calculate()); // error + mine = new MyClass(12); + Console.WriteLine("{0}", mine.value); // okay now + } +} \ No newline at end of file diff --git a/12 - Variable Scoping and Definite Assignment/Definite Assignment/File_3.cs b/12 - Variable Scoping and Definite Assignment/Definite Assignment/File_3.cs new file mode 100644 index 0000000..c32c78d --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/Definite Assignment/File_3.cs @@ -0,0 +1,38 @@ +// 13 - Variable Scoping and Definite Assignment\Definite Assignment +// copyright 2000 Eric Gunnerson +using System; +struct Complex +{ + public Complex(float real, float imaginary) + { + this.real = real; + this.imaginary = imaginary; + } + public override string ToString() + { + return(String.Format("({0}, {1})", real, imaginary)); + } + + public float real; + public float imaginary; +} + +class Test +{ + public static void Main() + { + Complex myNumber1; + Complex myNumber2; + Complex myNumber3; + + myNumber1 = new Complex(); + Console.WriteLine("Number 1: {0}", myNumber1); + + myNumber2 = new Complex(5.0F, 4.0F); + Console.WriteLine("Number 2: {0}", myNumber2); + + myNumber3.real = 1.5F; + myNumber3.imaginary = 15F; + Console.WriteLine("Number 3: {0}", myNumber3); + } +} \ No newline at end of file diff --git a/12 - Variable Scoping and Definite Assignment/File_.cs b/12 - Variable Scoping and Definite Assignment/File_.cs new file mode 100644 index 0000000..ca7d7fe --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/File_.cs @@ -0,0 +1,13 @@ +// 13 - Variable Scoping and Definite Assignment +// copyright 2000 Eric Gunnerson +using System; +class MyObject +{ + public MyObject(int x, int y) + { + this.x = x; + this.y = y; + } + int x; + int y; +} \ No newline at end of file diff --git a/12 - Variable Scoping and Definite Assignment/File_1.cs b/12 - Variable Scoping and Definite Assignment/File_1.cs new file mode 100644 index 0000000..fb67cd4 --- /dev/null +++ b/12 - Variable Scoping and Definite Assignment/File_1.cs @@ -0,0 +1,17 @@ +// 13 - Variable Scoping and Definite Assignment +// copyright 2000 Eric Gunnerson +// error +using System; +class MyObject +{ + public void Process() + { + int x = 12; + for (int y = 1; y < 10; y++) + { + // no way to name outer x here. + int x = 14; + Console.WriteLine("x = {0}", x); + } + } +} \ No newline at end of file diff --git a/13 - Operators and Expressions/Arithmetic Operators/Addition (+) over/Numeric Addition/Build1.bat b/13 - Operators and Expressions/Arithmetic Operators/Addition (+) over/Numeric Addition/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/13 - Operators and Expressions/Arithmetic Operators/Addition (+) over/Numeric Addition/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/13 - Operators and Expressions/Arithmetic Operators/Addition (+) over/Numeric Addition/File_1.cs b/13 - Operators and Expressions/Arithmetic Operators/Addition (+) over/Numeric Addition/File_1.cs new file mode 100644 index 0000000..bac3e06 --- /dev/null +++ b/13 - Operators and Expressions/Arithmetic Operators/Addition (+) over/Numeric Addition/File_1.cs @@ -0,0 +1,16 @@ +// 14 - Operators and Expressions\Arithmetic Operators\Addition (+) over\Numeric Addition +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + byte val1 = 200; + byte val2 = 201; + byte sum = (byte) (val1 + val2); // no exception + checked + { + byte sum2 = (byte) (val1 + val2); // exception + } + } +} \ No newline at end of file diff --git a/13 - Operators and Expressions/Built-In Operators/Build1.bat b/13 - Operators and Expressions/Built-In Operators/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/13 - Operators and Expressions/Built-In Operators/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/13 - Operators and Expressions/Built-In Operators/File_1.cs b/13 - Operators and Expressions/Built-In Operators/File_1.cs new file mode 100644 index 0000000..74bbc09 --- /dev/null +++ b/13 - Operators and Expressions/Built-In Operators/File_1.cs @@ -0,0 +1,16 @@ +// 14 - Operators and Expressions\Built-In Operators +// copyright 2000 Eric Gunnerson +// error +class Test +{ + public static void Main() + { + short s1 = 15; + short s2 = 16; + short ssum = (short) (s1 + s2); // cast is required + + int i1 = 15; + int i2 = 16; + int isum = i1 + i2; // no cast required + } +} \ No newline at end of file diff --git a/13 - Operators and Expressions/Checked and Unchecked Expressions/Build1.bat b/13 - Operators and Expressions/Checked and Unchecked Expressions/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/13 - Operators and Expressions/Checked and Unchecked Expressions/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/13 - Operators and Expressions/Checked and Unchecked Expressions/Build2.bat b/13 - Operators and Expressions/Checked and Unchecked Expressions/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/13 - Operators and Expressions/Checked and Unchecked Expressions/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/13 - Operators and Expressions/Checked and Unchecked Expressions/File_1.cs b/13 - Operators and Expressions/Checked and Unchecked Expressions/File_1.cs new file mode 100644 index 0000000..105aaee --- /dev/null +++ b/13 - Operators and Expressions/Checked and Unchecked Expressions/File_1.cs @@ -0,0 +1,16 @@ +// 14 - Operators and Expressions\Checked and Unchecked Expressions +// copyright 2000 Eric Gunnerson +using System; + +class Test +{ + public static void Main() + { + checked + { + byte a = 55; + byte b = 210; + byte c = (byte) (a + b); + } + } +} \ No newline at end of file diff --git a/13 - Operators and Expressions/Checked and Unchecked Expressions/File_2.cs b/13 - Operators and Expressions/Checked and Unchecked Expressions/File_2.cs new file mode 100644 index 0000000..b98c815 --- /dev/null +++ b/13 - Operators and Expressions/Checked and Unchecked Expressions/File_2.cs @@ -0,0 +1,16 @@ +// 14 - Operators and Expressions\Checked and Unchecked Expressions +// copyright 2000 Eric Gunnerson +using System; + +class Test +{ + public static void Main() + { + unchecked + { + byte a = 55; + byte b = 210; + byte c = (byte) (a + b); + } + } +} \ No newline at end of file diff --git a/13 - Operators and Expressions/Type operators/Is/Build1.bat b/13 - Operators and Expressions/Type operators/Is/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/13 - Operators and Expressions/Type operators/Is/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/13 - Operators and Expressions/Type operators/Is/File_1.cs b/13 - Operators and Expressions/Type operators/Is/File_1.cs new file mode 100644 index 0000000..aa85f9d --- /dev/null +++ b/13 - Operators and Expressions/Type operators/Is/File_1.cs @@ -0,0 +1,35 @@ +// 14 - Operators and Expressions\Type operators\Is +// copyright 2000 Eric Gunnerson +using System; +interface IAnnoy +{ + void PokeSister(string name); +} +class Brother: IAnnoy +{ + public void PokeSister(string name) + { + Console.WriteLine("Poking {0}", name); + } +} +class BabyBrother +{ +} +class Test +{ + public static void AnnoyHer(string sister, params object[] annoyers) + { + foreach (object o in annoyers) + { + if (o is IAnnoy) + { + IAnnoy annoyer = (IAnnoy) o; + annoyer.PokeSister(sister); + } + } + } + public static void Main() + { + Test.AnnoyHer("Jane", new Brother(), new BabyBrother()); + } +} \ No newline at end of file diff --git a/14 - Conversions/Conversions of Classes (Reference Types)/To an Interface the Object Might Implement/Build1.bat b/14 - Conversions/Conversions of Classes (Reference Types)/To an Interface the Object Might Implement/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/14 - Conversions/Conversions of Classes (Reference Types)/To an Interface the Object Might Implement/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/14 - Conversions/Conversions of Classes (Reference Types)/To an Interface the Object Might Implement/File_1.cs b/14 - Conversions/Conversions of Classes (Reference Types)/To an Interface the Object Might Implement/File_1.cs new file mode 100644 index 0000000..6ca2eb4 --- /dev/null +++ b/14 - Conversions/Conversions of Classes (Reference Types)/To an Interface the Object Might Implement/File_1.cs @@ -0,0 +1,60 @@ +// 15 - Conversions\Conversions of Classes (Reference Types)\To an Interface the Object Might Implement +// copyright 2000 Eric Gunnerson +using System; +interface IDebugDump +{ + string DumpObject(); +} +class Simple +{ + public Simple(int value) + { + this.value = value; + } + public override string ToString() + { + return(value.ToString()); + } + int value; +} +class Complicated: IDebugDump +{ + public Complicated(string name) + { + this.name = name; + } + public override string ToString() + { + return(name); + } + string IDebugDump.DumpObject() + { + return(String.Format( + "{0}\nLatency: {1}\nRequests: {2}\nFailures: {3}\n", + new object[] {name, latency, requestCount, failedCount} )); + } + string name; + int latency = 0; + int requestCount = 0; + int failedCount = 0; +} +class Test +{ + public static void DoConsoleDump(params object[] arr) + { + foreach (object o in arr) + { + IDebugDump dumper = o as IDebugDump; + if (dumper != null) + Console.WriteLine("{0}", dumper.DumpObject()); + else + Console.WriteLine("{0}", o); + } + } + public static void Main() + { + Simple s = new Simple(13); + Complicated c = new Complicated("Tracking Test"); + DoConsoleDump(s, c); + } +} \ No newline at end of file diff --git a/14 - Conversions/Conversions of Classes (Reference Types)/To the Base Class of an Object/Build1.bat b/14 - Conversions/Conversions of Classes (Reference Types)/To the Base Class of an Object/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/14 - Conversions/Conversions of Classes (Reference Types)/To the Base Class of an Object/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/14 - Conversions/Conversions of Classes (Reference Types)/To the Base Class of an Object/File_1.cs b/14 - Conversions/Conversions of Classes (Reference Types)/To the Base Class of an Object/File_1.cs new file mode 100644 index 0000000..4444ecd --- /dev/null +++ b/14 - Conversions/Conversions of Classes (Reference Types)/To the Base Class of an Object/File_1.cs @@ -0,0 +1,31 @@ +// 15 - Conversions\Conversions of Classes (Reference Types)\To the Base Class of an Object +// copyright 2000 Eric Gunnerson +using System; +public class Base +{ + public virtual void WhoAmI() + { + Console.WriteLine("Base"); + } +} +public class Derived: Base +{ + public override void WhoAmI() + { + Console.WriteLine("Derived"); + } +} +public class Test +{ + public static void Main() + { + Derived d = new Derived(); + Base b = d; + + b.WhoAmI(); + Derived d2 = (Derived) b; + + object o = d; + Derived d3 = (Derived) o; + } +} \ No newline at end of file diff --git a/14 - Conversions/Numeric Types/Build1.bat b/14 - Conversions/Numeric Types/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/14 - Conversions/Numeric Types/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/14 - Conversions/Numeric Types/Checked Conversions/Build1.bat b/14 - Conversions/Numeric Types/Checked Conversions/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/14 - Conversions/Numeric Types/Checked Conversions/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/14 - Conversions/Numeric Types/Checked Conversions/Build2.bat b/14 - Conversions/Numeric Types/Checked Conversions/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/14 - Conversions/Numeric Types/Checked Conversions/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/14 - Conversions/Numeric Types/Checked Conversions/File_1.cs b/14 - Conversions/Numeric Types/Checked Conversions/File_1.cs new file mode 100644 index 0000000..31d0136 --- /dev/null +++ b/14 - Conversions/Numeric Types/Checked Conversions/File_1.cs @@ -0,0 +1,15 @@ +// 15 - Conversions\Numeric Types\Checked Conversions +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + checked + { + uint value1 = 312; + byte value2 = (byte) value1; + Console.WriteLine("Value: {0}", value2); + } + } +} \ No newline at end of file diff --git a/14 - Conversions/Numeric Types/Checked Conversions/File_2.cs b/14 - Conversions/Numeric Types/Checked Conversions/File_2.cs new file mode 100644 index 0000000..9d0bbb6 --- /dev/null +++ b/14 - Conversions/Numeric Types/Checked Conversions/File_2.cs @@ -0,0 +1,15 @@ +// 15 - Conversions\Numeric Types\Checked Conversions +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + uint value1 = 312; + byte value2; + + value2 = unchecked((byte) value1); // never checked + value2 = (byte) value1; // checked if /checked + value2 = checked((byte) value1); // always checked + } +} \ No newline at end of file diff --git a/14 - Conversions/Numeric Types/Conversions and Member Lookup/Build1.bat b/14 - Conversions/Numeric Types/Conversions and Member Lookup/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/14 - Conversions/Numeric Types/Conversions and Member Lookup/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/14 - Conversions/Numeric Types/Conversions and Member Lookup/Build3.bat b/14 - Conversions/Numeric Types/Conversions and Member Lookup/Build3.bat new file mode 100644 index 0000000..b764232 --- /dev/null +++ b/14 - Conversions/Numeric Types/Conversions and Member Lookup/Build3.bat @@ -0,0 +1 @@ +csc File_3.cs diff --git a/14 - Conversions/Numeric Types/Conversions and Member Lookup/File_1.cs b/14 - Conversions/Numeric Types/Conversions and Member Lookup/File_1.cs new file mode 100644 index 0000000..d8cacd1 --- /dev/null +++ b/14 - Conversions/Numeric Types/Conversions and Member Lookup/File_1.cs @@ -0,0 +1,28 @@ +// 15 - Conversions\Numeric Types\Conversions and Member Lookup +// copyright 2000 Eric Gunnerson +using System; +class Conv +{ + public static void Process(sbyte value) + { + Console.WriteLine("sbyte {0}", value); + } + public static void Process(short value) + { + Console.WriteLine("short {0}", value); + } + public static void Process(int value) + { + Console.WriteLine("int {0}", value); + } +} +class Test +{ + public static void Main() + { + int value1 = 2; + sbyte value2 = 1; + Conv.Process(value1); + Conv.Process(value2); + } +} \ No newline at end of file diff --git a/14 - Conversions/Numeric Types/Conversions and Member Lookup/File_3.cs b/14 - Conversions/Numeric Types/Conversions and Member Lookup/File_3.cs new file mode 100644 index 0000000..2e15abd --- /dev/null +++ b/14 - Conversions/Numeric Types/Conversions and Member Lookup/File_3.cs @@ -0,0 +1,22 @@ +// 15 - Conversions\Numeric Types\Conversions and Member Lookup +// copyright 2000 Eric Gunnerson +using System; +class Conv +{ + public static void Process(short value) + { + Console.WriteLine("short {0}", value); + } + public static void Process(ushort value) + { + Console.WriteLine("ushort {0}", value); + } +} +class Test +{ + public static void Main() + { + byte value = 3; + Conv.Process(value); + } +} \ No newline at end of file diff --git a/14 - Conversions/Numeric Types/Explicit Numeric Conversions/Build1.bat b/14 - Conversions/Numeric Types/Explicit Numeric Conversions/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/14 - Conversions/Numeric Types/Explicit Numeric Conversions/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/14 - Conversions/Numeric Types/Explicit Numeric Conversions/File_1.cs b/14 - Conversions/Numeric Types/Explicit Numeric Conversions/File_1.cs new file mode 100644 index 0000000..3c6f8b6 --- /dev/null +++ b/14 - Conversions/Numeric Types/Explicit Numeric Conversions/File_1.cs @@ -0,0 +1,12 @@ +// 15 - Conversions\Numeric Types\Explicit Numeric Conversions +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + uint value1 = 312; + byte value2 = (byte) value1; + Console.WriteLine("Value2: {0}", value2); + } +} \ No newline at end of file diff --git a/14 - Conversions/Numeric Types/File_1.cs b/14 - Conversions/Numeric Types/File_1.cs new file mode 100644 index 0000000..dafd441 --- /dev/null +++ b/14 - Conversions/Numeric Types/File_1.cs @@ -0,0 +1,18 @@ +// 15 - Conversions\Numeric Types +// copyright 2000 Eric Gunnerson +class Test +{ + public static void Main() + { + // all implicit + sbyte v = 55; + short v2 = v; + int v3 = v2; + long v4 = v3; + + // explicit to "smaller" types + v3 = (int) v4; + v2 = (short) v3; + v = (sbyte) v2; + } +} \ No newline at end of file diff --git a/15 - Arrays/Array Conversions/Build1.bat b/15 - Arrays/Array Conversions/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/15 - Arrays/Array Conversions/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/15 - Arrays/Array Conversions/File_1.cs b/15 - Arrays/Array Conversions/File_1.cs new file mode 100644 index 0000000..6bae418 --- /dev/null +++ b/15 - Arrays/Array Conversions/File_1.cs @@ -0,0 +1,18 @@ +// 16 - Arrays\Array Conversions +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void PrintArray(object[] arr) + { + foreach (object obj in arr) + Console.WriteLine("Word: {0}", obj); + } + public static void Main() + { + string s = "I will not buy this record, it is scratched."; + char[] separators = {' '}; + string[] words = s.Split(separators); + PrintArray(words); + } +} \ No newline at end of file diff --git a/15 - Arrays/Arrays of Reference Types/Build1.bat b/15 - Arrays/Arrays of Reference Types/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/15 - Arrays/Arrays of Reference Types/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/15 - Arrays/Arrays of Reference Types/Build2.bat b/15 - Arrays/Arrays of Reference Types/Build2.bat new file mode 100644 index 0000000..27777ef --- /dev/null +++ b/15 - Arrays/Arrays of Reference Types/Build2.bat @@ -0,0 +1 @@ +csc File_2.cs diff --git a/15 - Arrays/Arrays of Reference Types/File_1.cs b/15 - Arrays/Arrays of Reference Types/File_1.cs new file mode 100644 index 0000000..595fd6c --- /dev/null +++ b/15 - Arrays/Arrays of Reference Types/File_1.cs @@ -0,0 +1,19 @@ +// 16 - Arrays\Arrays of Reference Types +// copyright 2000 Eric Gunnerson +class Employee +{ + public void LoadFromDatabase(int employeeID) + { + // load code here + } +} +class Test +{ + public static void Main() + { + Employee[] emps = new Employee[3]; + emps[0].LoadFromDatabase(15); + emps[1].LoadFromDatabase(35); + emps[2].LoadFromDatabase(255); + } +} \ No newline at end of file diff --git a/15 - Arrays/Arrays of Reference Types/File_2.cs b/15 - Arrays/Arrays of Reference Types/File_2.cs new file mode 100644 index 0000000..53a75d8 --- /dev/null +++ b/15 - Arrays/Arrays of Reference Types/File_2.cs @@ -0,0 +1,21 @@ +// 16 - Arrays\Arrays of Reference Types +// copyright 2000 Eric Gunnerson +class Employee +{ + public static Employee LoadFromDatabase(int employeeID) + { + Employee emp = new Employee(); + // load code here + return(emp); + } +} +class Test +{ + public static void Main() + { + Employee[] emps = new Employee[3]; + emps[0] = Employee.LoadFromDatabase(15); + emps[1] = Employee.LoadFromDatabase(35); + emps[2] = Employee.LoadFromDatabase(255); + } +} \ No newline at end of file diff --git a/15 - Arrays/Multidimensional and Jagged Arrays/Jagged Arrays/Build1.bat b/15 - Arrays/Multidimensional and Jagged Arrays/Jagged Arrays/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/15 - Arrays/Multidimensional and Jagged Arrays/Jagged Arrays/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/15 - Arrays/Multidimensional and Jagged Arrays/Jagged Arrays/File_1.cs b/15 - Arrays/Multidimensional and Jagged Arrays/Jagged Arrays/File_1.cs new file mode 100644 index 0000000..8f80e9d --- /dev/null +++ b/15 - Arrays/Multidimensional and Jagged Arrays/Jagged Arrays/File_1.cs @@ -0,0 +1,21 @@ +// 16 - Arrays\Multidimensional and Jagged Arrays\Jagged Arrays +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + int[][] matrix = {new int[5], new int[4], new int[2] }; + matrix[0][3] = 4; + matrix[1][1] = 8; + matrix[2][0] = 5; + + for (int i = 0; i < matrix.Length; i++) + { + for (int j = 0; j < matrix[i].Length; j++) + { + Console.WriteLine("matrix[{0}, {1}] = {2}", i, j, matrix[i][j]); + } + } + } +} \ No newline at end of file diff --git a/15 - Arrays/Multidimensional and Jagged Arrays/Multidimensional Arrays/Build1.bat b/15 - Arrays/Multidimensional and Jagged Arrays/Multidimensional Arrays/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/15 - Arrays/Multidimensional and Jagged Arrays/Multidimensional Arrays/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/15 - Arrays/Multidimensional and Jagged Arrays/Multidimensional Arrays/File_1.cs b/15 - Arrays/Multidimensional and Jagged Arrays/Multidimensional Arrays/File_1.cs new file mode 100644 index 0000000..b053bf3 --- /dev/null +++ b/15 - Arrays/Multidimensional and Jagged Arrays/Multidimensional Arrays/File_1.cs @@ -0,0 +1,18 @@ +// 16 - Arrays\Multidimensional and Jagged Arrays\Multidimensional Arrays +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + int[,] matrix = { {1, 1}, {2, 2}, {3, 5}, {4, 5}, {134, 44} }; + + for (int i = 0; i < matrix.GetLength(0); i++) + { + for (int j = 0; j < matrix.GetLength(1); j++) + { + Console.WriteLine("matrix[{0}, {1}] = {2}", i, j, matrix[i, j]); + } + } + } +} \ No newline at end of file diff --git a/15 - Arrays/The System.Array Type/Reverse/Build1.bat b/15 - Arrays/The System.Array Type/Reverse/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/15 - Arrays/The System.Array Type/Reverse/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/15 - Arrays/The System.Array Type/Reverse/File_1.cs b/15 - Arrays/The System.Array Type/Reverse/File_1.cs new file mode 100644 index 0000000..cc2dbd5 --- /dev/null +++ b/15 - Arrays/The System.Array Type/Reverse/File_1.cs @@ -0,0 +1,15 @@ +// 16 - Arrays\The System.Array Type\Reverse +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + int[] arr = {5, 6, 7}; + Array.Reverse(arr); + foreach (int value in arr) + { + Console.WriteLine("Value: {0}", value); + } + } +} \ No newline at end of file diff --git a/16 - Properties/Accessors/Build1.bat b/16 - Properties/Accessors/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/16 - Properties/Accessors/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/16 - Properties/Accessors/File_1.cs b/16 - Properties/Accessors/File_1.cs new file mode 100644 index 0000000..2274ce7 --- /dev/null +++ b/16 - Properties/Accessors/File_1.cs @@ -0,0 +1,18 @@ +// 18 - Properties\Accessors +// copyright 2000 Eric Gunnerson +class Test +{ + private string name; + + public string Name + { + get + { + return name; + } + set + { + name = value; + } + } +} \ No newline at end of file diff --git a/16 - Properties/Chapter 16 properties/Chapter 16 properties.csproj b/16 - Properties/Chapter 16 properties/Chapter 16 properties.csproj new file mode 100644 index 0000000..ed96699 --- /dev/null +++ b/16 - Properties/Chapter 16 properties/Chapter 16 properties.csproj @@ -0,0 +1,58 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {DDF3BE3D-C04E-48AF-8EBF-7C543B0D3DBB} + Exe + Properties + Chapter_16_properties + Chapter 16 properties + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/16 - Properties/Chapter 16 properties/Chapter 16 properties.csproj.user b/16 - Properties/Chapter 16 properties/Chapter 16 properties.csproj.user new file mode 100644 index 0000000..ace9a86 --- /dev/null +++ b/16 - Properties/Chapter 16 properties/Chapter 16 properties.csproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/16 - Properties/Chapter 16 properties/Chapter 16 properties.sln b/16 - Properties/Chapter 16 properties/Chapter 16 properties.sln new file mode 100644 index 0000000..5de2694 --- /dev/null +++ b/16 - Properties/Chapter 16 properties/Chapter 16 properties.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C# Express 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chapter 16 properties", "Chapter 16 properties.csproj", "{DDF3BE3D-C04E-48AF-8EBF-7C543B0D3DBB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DDF3BE3D-C04E-48AF-8EBF-7C543B0D3DBB}.Debug|x86.ActiveCfg = Debug|x86 + {DDF3BE3D-C04E-48AF-8EBF-7C543B0D3DBB}.Debug|x86.Build.0 = Debug|x86 + {DDF3BE3D-C04E-48AF-8EBF-7C543B0D3DBB}.Release|x86.ActiveCfg = Release|x86 + {DDF3BE3D-C04E-48AF-8EBF-7C543B0D3DBB}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/16 - Properties/Chapter 16 properties/Chapter 16 properties.suo b/16 - Properties/Chapter 16 properties/Chapter 16 properties.suo new file mode 100644 index 0000000..06a5cc1 Binary files /dev/null and b/16 - Properties/Chapter 16 properties/Chapter 16 properties.suo differ diff --git a/16 - Properties/Chapter 16 properties/Program.cs b/16 - Properties/Chapter 16 properties/Program.cs new file mode 100644 index 0000000..b376d18 --- /dev/null +++ b/16 - Properties/Chapter 16 properties/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16_properties +{ + class Program + { + static void Main(string[] args) + { + + } + +string m_name; +public string Name +{ + get { return m_name; } + set { m_name = value; } +} + } +} diff --git a/16 - Properties/Chapter 16 properties/Properties/AssemblyInfo.cs b/16 - Properties/Chapter 16 properties/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f8dba17 --- /dev/null +++ b/16 - Properties/Chapter 16 properties/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Chapter 16 properties")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Chapter 16 properties")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d9e85b94-d6ae-4d0c-81b4-d16d345ab5c4")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/16 - Properties/Chapter 16 properties/Test.cs b/16 - Properties/Chapter 16 properties/Test.cs new file mode 100644 index 0000000..5767cfb --- /dev/null +++ b/16 - Properties/Chapter 16 properties/Test.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16_properties +{ + class Test + { + public string Name { get; set; } + } + +} diff --git a/16 - Properties/Chapter 16 properties/bin/Debug/Chapter 16 properties.vshost.exe b/16 - Properties/Chapter 16 properties/bin/Debug/Chapter 16 properties.vshost.exe new file mode 100644 index 0000000..bb84a51 Binary files /dev/null and b/16 - Properties/Chapter 16 properties/bin/Debug/Chapter 16 properties.vshost.exe differ diff --git a/16 - Properties/Chapter 16 properties/bin/Release/Chapter 16 properties.exe b/16 - Properties/Chapter 16 properties/bin/Release/Chapter 16 properties.exe new file mode 100644 index 0000000..06568b4 Binary files /dev/null and b/16 - Properties/Chapter 16 properties/bin/Release/Chapter 16 properties.exe differ diff --git a/16 - Properties/Chapter 16 properties/bin/Release/Chapter 16 properties.pdb b/16 - Properties/Chapter 16 properties/bin/Release/Chapter 16 properties.pdb new file mode 100644 index 0000000..04093ea Binary files /dev/null and b/16 - Properties/Chapter 16 properties/bin/Release/Chapter 16 properties.pdb differ diff --git a/16 - Properties/Chapter 16 properties/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/16 - Properties/Chapter 16 properties/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..22b3ee2 Binary files /dev/null and b/16 - Properties/Chapter 16 properties/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/16 - Properties/Chapter 16 properties/obj/x86/Release/Chapter 16 properties.csproj.FileListAbsolute.txt b/16 - Properties/Chapter 16 properties/obj/x86/Release/Chapter 16 properties.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..004c76b --- /dev/null +++ b/16 - Properties/Chapter 16 properties/obj/x86/Release/Chapter 16 properties.csproj.FileListAbsolute.txt @@ -0,0 +1,5 @@ +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 16 properties\bin\Release\Chapter 16 properties.exe +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 16 properties\bin\Release\Chapter 16 properties.pdb +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 16 properties\obj\x86\Release\ResolveAssemblyReference.cache +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 16 properties\obj\x86\Release\Chapter 16 properties.exe +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 16 properties\obj\x86\Release\Chapter 16 properties.pdb diff --git a/16 - Properties/Chapter 16 properties/obj/x86/Release/Chapter 16 properties.exe b/16 - Properties/Chapter 16 properties/obj/x86/Release/Chapter 16 properties.exe new file mode 100644 index 0000000..06568b4 Binary files /dev/null and b/16 - Properties/Chapter 16 properties/obj/x86/Release/Chapter 16 properties.exe differ diff --git a/16 - Properties/Chapter 16 properties/obj/x86/Release/Chapter 16 properties.pdb b/16 - Properties/Chapter 16 properties/obj/x86/Release/Chapter 16 properties.pdb new file mode 100644 index 0000000..04093ea Binary files /dev/null and b/16 - Properties/Chapter 16 properties/obj/x86/Release/Chapter 16 properties.pdb differ diff --git a/16 - Properties/Chapter 16 properties/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache b/16 - Properties/Chapter 16 properties/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..9da5530 Binary files /dev/null and b/16 - Properties/Chapter 16 properties/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/16 - Properties/Property Efficiency/Build1.bat b/16 - Properties/Property Efficiency/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/16 - Properties/Property Efficiency/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/16 - Properties/Property Efficiency/File_1.cs b/16 - Properties/Property Efficiency/File_1.cs new file mode 100644 index 0000000..3aeb5c0 --- /dev/null +++ b/16 - Properties/Property Efficiency/File_1.cs @@ -0,0 +1,18 @@ +// 18 - Properties\Property Efficiency +// copyright 2000 Eric Gunnerson +class Test +{ + private string name; + + public string Name + { + get + { + return name; + } + set + { + name = value; + } + } +} \ No newline at end of file diff --git a/16 - Properties/Side Effects When Setting Values/Build1.bat b/16 - Properties/Side Effects When Setting Values/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/16 - Properties/Side Effects When Setting Values/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/16 - Properties/Side Effects When Setting Values/File_1.cs b/16 - Properties/Side Effects When Setting Values/File_1.cs new file mode 100644 index 0000000..bcc6c76 --- /dev/null +++ b/16 - Properties/Side Effects When Setting Values/File_1.cs @@ -0,0 +1,64 @@ +// 18 - Properties\Side Effects When Setting Values +// copyright 2000 Eric Gunnerson +using System; +using System.Collections; +class Basket +{ + internal void UpdateTotal() + { + total = 0; + foreach (BasketItem item in items) + { + total += item.Total; + } + } + + ArrayList items = new ArrayList(); + Decimal total; +} +class BasketItem +{ + BasketItem(Basket basket) + { + this.basket = basket; + } + public int Quantity + { + get + { + return(quantity); + } + set + { + quantity = value; + basket.UpdateTotal(); + } + } + public Decimal Price + { + get + { + return(price); + } + set + { + price = value; + basket.UpdateTotal(); + } + } + public Decimal Total + { + get + { + // volume discount; 10% if 10 or more are purchased + if (quantity >= 10) + return(quantity * price * 0.90m); + else + return(quantity * price); + } + } + + int quantity; // count of the item + Decimal price; // price of the item + Basket basket; // reference back to the basket +} \ No newline at end of file diff --git a/16 - Properties/Static Properties/Build1.bat b/16 - Properties/Static Properties/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/16 - Properties/Static Properties/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/16 - Properties/Static Properties/File_1.cs b/16 - Properties/Static Properties/File_1.cs new file mode 100644 index 0000000..e589a61 --- /dev/null +++ b/16 - Properties/Static Properties/File_1.cs @@ -0,0 +1,44 @@ +// 18 - Properties\Static Properties +// copyright 2000 Eric Gunnerson +class Color +{ + public Color(int red, int green, int blue) + { + this.red = red; + this.green = green; + this.blue = blue; + } + + int red; + int green; + int blue; + + public static Color Red + { + get + { + return(new Color(255, 0, 0)); + } + } + public static Color Green + { + get + { + return(new Color(0, 255, 0)); + } + } + public static Color Blue + { + get + { + return(new Color(0, 0, 255)); + } + } +} +class Test +{ + static void Main() + { + Color background = Color.Red; + } +} \ No newline at end of file diff --git a/16 - Properties/Use of Properties/Build1.bat b/16 - Properties/Use of Properties/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/16 - Properties/Use of Properties/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/16 - Properties/Use of Properties/File_1.cs b/16 - Properties/Use of Properties/File_1.cs new file mode 100644 index 0000000..dc9a57b --- /dev/null +++ b/16 - Properties/Use of Properties/File_1.cs @@ -0,0 +1,39 @@ +// 18 - Properties\Use of Properties +// copyright 2000 Eric Gunnerson +using System; +class Auto +{ + public Auto(int id, string name) + { + this.id = id; + this.name = name; + } + + // query to find # produced + public int ProductionCount + { + get + { + if (productionCount == -1) + { + // fetch count from database here. + } + return(productionCount); + } + } + public int SalesCount + { + get + { + if (salesCount == -1) + { + // query each dealership for data + } + return(salesCount); + } + } + string name; + int id; + int productionCount = -1; + int salesCount = -1; +} \ No newline at end of file diff --git a/16 - Properties/Virtual Properties/Build1.bat b/16 - Properties/Virtual Properties/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/16 - Properties/Virtual Properties/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/16 - Properties/Virtual Properties/File_1.cs b/16 - Properties/Virtual Properties/File_1.cs new file mode 100644 index 0000000..b861b87 --- /dev/null +++ b/16 - Properties/Virtual Properties/File_1.cs @@ -0,0 +1,31 @@ +// 18 - Properties\Virtual Properties +// copyright 2000 Eric Gunnerson +using System; + +public abstract class DrawingObject +{ + public abstract string Name + { + get; + } +} +class Circle: DrawingObject +{ + string name = "Circle"; + + public override string Name + { + get + { + return(name); + } + } +} +class Test +{ + public static void Main() + { + DrawingObject d = new Circle(); + Console.WriteLine("Name: {0}", d.Name); + } +} \ No newline at end of file diff --git a/17 - Generics/Chapter 16 - Generic Types/Auto.cs b/17 - Generics/Chapter 16 - Generic Types/Auto.cs new file mode 100644 index 0000000..f459d34 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/Auto.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ + class Auto + { + } +} diff --git a/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.csproj b/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.csproj new file mode 100644 index 0000000..75c3ca5 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.csproj @@ -0,0 +1,68 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {8566616D-B466-40AA-B4AE-E27ACEA9E621} + Exe + Properties + Chapter_16___Generic_Types + Chapter 16 - Generic Types + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.csproj.user b/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.csproj.user new file mode 100644 index 0000000..ace9a86 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.csproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.sln b/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.sln new file mode 100644 index 0000000..935b555 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C# Express 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chapter 16 - Generic Types", "Chapter 16 - Generic Types.csproj", "{8566616D-B466-40AA-B4AE-E27ACEA9E621}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8566616D-B466-40AA-B4AE-E27ACEA9E621}.Debug|x86.ActiveCfg = Debug|x86 + {8566616D-B466-40AA-B4AE-E27ACEA9E621}.Debug|x86.Build.0 = Debug|x86 + {8566616D-B466-40AA-B4AE-E27ACEA9E621}.Release|x86.ActiveCfg = Release|x86 + {8566616D-B466-40AA-B4AE-E27ACEA9E621}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.suo b/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.suo new file mode 100644 index 0000000..c0ca5d0 Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/Chapter 16 - Generic Types.suo differ diff --git a/17 - Generics/Chapter 16 - Generic Types/GenericCollectionCovariance.cs b/17 - Generics/Chapter 16 - Generic Types/GenericCollectionCovariance.cs new file mode 100644 index 0000000..60ce49f --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/GenericCollectionCovariance.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ +interface IFirstItem // remove 'out' to show the compiler error. +{ + T GetFirstItem(); + //void NotLegal(T parameter); // also generates an error. +} +class MyFirstList : List, IFirstItem +{ + public MyFirstList() { } + + public T GetFirstItem() + { + return this[0]; + } +} + + class GenericCollectionCovariance + { + void Example() + { + MyFirstList sedans = new MyFirstList(); + sedans.Add(new Sedan()); + + TestService(); + } + +void TestService() +{ + MyFirstList sedans = new MyFirstList(); + sedans.Add(new Sedan()); + + PerformService(sedans); +} +void PerformService(IFirstItem autos) +{ +} + } +} diff --git a/17 - Generics/Chapter 16 - Generic Types/GenericContravariance.cs b/17 - Generics/Chapter 16 - Generic Types/GenericContravariance.cs new file mode 100644 index 0000000..88f75c4 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/GenericContravariance.cs @@ -0,0 +1,31 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ +interface IEqual +{ + bool IsEqual(T x, T y); +} +class Comparer : IEqual +{ + public bool IsEqual(object x, object y) + { + return true; + } +} +class GenericContravariance +{ + void Example() + { + Comparer comparer = new Comparer(); + TestEquality(comparer); + } + void TestEquality(IEqual equalizer) + { + } +} +} diff --git a/17 - Generics/Chapter 16 - Generic Types/IntList.cs b/17 - Generics/Chapter 16 - Generic Types/IntList.cs new file mode 100644 index 0000000..67132d8 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/IntList.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ +public class IntList +{ + int m_count = 0; + int[] m_values; + + public IntList(int capacity) + { + m_values = new int[capacity]; + } + public void Add(int value) + { + m_values[m_count] = value; + m_count++; + } + public int this[int index] + { + get { return m_values[index];} + set { m_values[index] = value; } + } + public int Count { get { return m_count; } } +} +} diff --git a/17 - Generics/Chapter 16 - Generic Types/MyConstructedList.cs b/17 - Generics/Chapter 16 - Generic Types/MyConstructedList.cs new file mode 100644 index 0000000..178530b --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/MyConstructedList.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ + class MyConstructedList where T : new() + { + int m_count = 0; + T[] m_values; + +public MyConstructedList(int capacity) +{ + m_values = new T[capacity]; + for (int i = 0; i < capacity; i++) + { + m_values[i] = new T(); + } +} + public void Add(T value) + { + m_values[m_count] = value; + m_count++; + } + public T this[int index] + { + get { return m_values[index]; } + set { m_values[index] = value; } + } + public int Count { get { return m_count; } } + } +} diff --git a/17 - Generics/Chapter 16 - Generic Types/MyList.cs b/17 - Generics/Chapter 16 - Generic Types/MyList.cs new file mode 100644 index 0000000..885d90b --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/MyList.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ + interface IMyList + { + void Add(T value); + } + +class MyList +{ + int m_count = 0; + T[] m_values; + + public MyList(int capacity) + { + m_values = new T[capacity]; + } + public void Add(T value) + { + m_values[m_count] = value; + m_count++; + } + public T this[int index] + { + get { return m_values[index]; } + set { m_values[index] = value; } + } + public int Count { get { return m_count; } } + + public delegate void ItemAdded(T newItem); +} + + + +class NewIntList : MyList, IMyList +{ + NewIntList(int capacity) : base(capacity) { } +} +} diff --git a/17 - Generics/Chapter 16 - Generic Types/MySortedList.cs b/17 - Generics/Chapter 16 - Generic Types/MySortedList.cs new file mode 100644 index 0000000..3dd412a --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/MySortedList.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ + class MySortedList where T: IComparable + { + int m_count = 0; + T[] m_values; + + public MySortedList(int capacity) + { + m_values = new T[capacity]; + } + public void Add(T value) + { + m_values[m_count] = value; + m_count++; + } + void Sort() + { + // You shouldn't write your own sort routines, so I won't write one here. + // I will include one comparison, so that a constraint is required. + int x = 0; + int y = 1; + if (m_values[x].CompareTo(m_values[y]) > 0) + { + } + } + public T this[int index] + { + get { return m_values[index]; } + set { m_values[index] = value; } + } + public int Count { get { return m_count; } } + } +} diff --git a/17 - Generics/Chapter 16 - Generic Types/Program.cs b/17 - Generics/Chapter 16 - Generic Types/Program.cs new file mode 100644 index 0000000..af9afe1 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/Program.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ + class Program + { + static void Main(string[] args) + { + IntList intList = new IntList(5); + intList.Add(15); + intList.Add(22); + + Console.WriteLine(intList.Count); + for (int i = 0; i < intList.Count; i++) + { + Console.WriteLine(intList[i]); + } + + MyList l = new MyList(33); + MyConstructedList m; + + + List list1 = new List(); + List list2 = new List(); + + + list1.Add("All"); + list1.Add("base"); + list1.Add("belong"); + list1.Add("us"); + + list2.Add("your"); + list2.Add("are"); + list2.Add("to"); + list2.Add("!"); + + foreach (string word in Shuffler.Shuffle(list1, list2)) + { + Console.WriteLine(word); + } + + ReferenceArrayCovariance.ReferenceCovariance(); + ReferenceArrayCovariance.ArrayCovariance(); + } + } + +} diff --git a/17 - Generics/Chapter 16 - Generic Types/Properties/AssemblyInfo.cs b/17 - Generics/Chapter 16 - Generic Types/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..cb93f89 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Chapter 16 - Generic Types")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Chapter 16 - Generic Types")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("2c2f7d1c-26b3-4a95-85aa-0bddc8bbfb8e")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/17 - Generics/Chapter 16 - Generic Types/ReferenceArrayCovariance.cs b/17 - Generics/Chapter 16 - Generic Types/ReferenceArrayCovariance.cs new file mode 100644 index 0000000..0e0bbe6 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/ReferenceArrayCovariance.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ + public class ReferenceArrayCovariance + { + public static void ReferenceCovariance() + { + Sedan dodgeDart = new Sedan(); + + Auto currentCar = dodgeDart; + + } + +public static void ArrayCovariance() +{ + Sedan[] sedans = new Sedan[1]; + sedans[0] = new Sedan(); + + Auto[] autos = sedans; + + autos[0] = new Roadster(); +} + } +} diff --git a/17 - Generics/Chapter 16 - Generic Types/Roadster.cs b/17 - Generics/Chapter 16 - Generic Types/Roadster.cs new file mode 100644 index 0000000..3db67e6 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/Roadster.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ + class Roadster: Auto + { + } +} diff --git a/17 - Generics/Chapter 16 - Generic Types/Sedan.cs b/17 - Generics/Chapter 16 - Generic Types/Sedan.cs new file mode 100644 index 0000000..370e74d --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/Sedan.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ + class Sedan: Auto + { + } +} diff --git a/17 - Generics/Chapter 16 - Generic Types/Shuffler.cs b/17 - Generics/Chapter 16 - Generic Types/Shuffler.cs new file mode 100644 index 0000000..3c95c71 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/Shuffler.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_16___Generic_Types +{ + public class Shuffler + { +#if nongeneric +public static List Shuffle(List list1, List list2) +{ + List shuffled = new List(); + + for (int i = 0; i < list1.Count; i++) + { + shuffled.Add(list1[i]); + shuffled.Add(list2[i]); + } + + return shuffled; +} +#else +public static List Shuffle(List list1, List list2) +{ + List shuffled = new List(); + + for (int i = 0; i < list1.Count; i++) + { + shuffled.Add(list1[i]); + shuffled.Add(list2[i]); + } + + return shuffled; +} +#endif + } +} diff --git a/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.exe b/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.exe new file mode 100644 index 0000000..fdead2b Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.exe differ diff --git a/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.pdb b/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.pdb new file mode 100644 index 0000000..60592a6 Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.pdb differ diff --git a/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.vshost.exe b/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.vshost.exe new file mode 100644 index 0000000..bb84a51 Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.vshost.exe differ diff --git a/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.vshost.exe.manifest b/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.vshost.exe.manifest new file mode 100644 index 0000000..061c9ca --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/bin/Debug/Chapter 16 - Generic Types.vshost.exe.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/17 - Generics/Chapter 16 - Generic Types/bin/Release/Chapter 16 - Generic Types.exe b/17 - Generics/Chapter 16 - Generic Types/bin/Release/Chapter 16 - Generic Types.exe new file mode 100644 index 0000000..7642992 Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/bin/Release/Chapter 16 - Generic Types.exe differ diff --git a/17 - Generics/Chapter 16 - Generic Types/bin/Release/Chapter 16 - Generic Types.pdb b/17 - Generics/Chapter 16 - Generic Types/bin/Release/Chapter 16 - Generic Types.pdb new file mode 100644 index 0000000..8f00974 Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/bin/Release/Chapter 16 - Generic Types.pdb differ diff --git a/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/Chapter 16 - Generic Types.csproj.FileListAbsolute.txt b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/Chapter 16 - Generic Types.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..e8aaeed --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/Chapter 16 - Generic Types.csproj.FileListAbsolute.txt @@ -0,0 +1,5 @@ +D:\data\booknew\Chapters\code\Chapter 16 - Generic Types\bin\Debug\Chapter 16 - Generic Types.exe +D:\data\booknew\Chapters\code\Chapter 16 - Generic Types\bin\Debug\Chapter 16 - Generic Types.pdb +D:\data\booknew\Chapters\code\Chapter 16 - Generic Types\obj\x86\Debug\ResolveAssemblyReference.cache +D:\data\booknew\Chapters\code\Chapter 16 - Generic Types\obj\x86\Debug\Chapter 16 - Generic Types.exe +D:\data\booknew\Chapters\code\Chapter 16 - Generic Types\obj\x86\Debug\Chapter 16 - Generic Types.pdb diff --git a/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/Chapter 16 - Generic Types.exe b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/Chapter 16 - Generic Types.exe new file mode 100644 index 0000000..fdead2b Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/Chapter 16 - Generic Types.exe differ diff --git a/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/Chapter 16 - Generic Types.pdb b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/Chapter 16 - Generic Types.pdb new file mode 100644 index 0000000..60592a6 Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/Chapter 16 - Generic Types.pdb differ diff --git a/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..320cfa7 Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/Chapter 16 - Generic Types.csproj.FileListAbsolute.txt b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/Chapter 16 - Generic Types.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..bc81cd3 --- /dev/null +++ b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/Chapter 16 - Generic Types.csproj.FileListAbsolute.txt @@ -0,0 +1,10 @@ +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 16 - Generic Types\bin\Release\Chapter 16 - Generic Types.exe +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 16 - Generic Types\bin\Release\Chapter 16 - Generic Types.pdb +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 16 - Generic Types\obj\x86\Release\ResolveAssemblyReference.cache +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 16 - Generic Types\obj\x86\Release\Chapter 16 - Generic Types.exe +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 16 - Generic Types\obj\x86\Release\Chapter 16 - Generic Types.pdb +D:\data\booknew\Chapters\code\Chapter 16 - Generic Types\obj\x86\Release\Chapter 16 - Generic Types.exe +D:\data\booknew\Chapters\code\Chapter 16 - Generic Types\obj\x86\Release\Chapter 16 - Generic Types.pdb +D:\data\booknew\Chapters\code\Chapter 16 - Generic Types\bin\Release\Chapter 16 - Generic Types.exe +D:\data\booknew\Chapters\code\Chapter 16 - Generic Types\bin\Release\Chapter 16 - Generic Types.pdb +D:\data\booknew\Chapters\code\Chapter 16 - Generic Types\obj\x86\Release\ResolveAssemblyReference.cache diff --git a/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/Chapter 16 - Generic Types.exe b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/Chapter 16 - Generic Types.exe new file mode 100644 index 0000000..7642992 Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/Chapter 16 - Generic Types.exe differ diff --git a/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..c7c5b89 Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/ResolveAssemblyReference.cache b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/ResolveAssemblyReference.cache new file mode 100644 index 0000000..553d1aa Binary files /dev/null and b/17 - Generics/Chapter 16 - Generic Types/obj/x86/Release/ResolveAssemblyReference.cache differ diff --git a/17 - Generics/Generics/Generics.sln b/17 - Generics/Generics/Generics.sln new file mode 100644 index 0000000..922c53a --- /dev/null +++ b/17 - Generics/Generics/Generics.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Generics", "Generics\Generics.csproj", "{B2A4D91C-34E6-4E60-BEEB-0B9327AA4C36}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B2A4D91C-34E6-4E60-BEEB-0B9327AA4C36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B2A4D91C-34E6-4E60-BEEB-0B9327AA4C36}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2A4D91C-34E6-4E60-BEEB-0B9327AA4C36}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B2A4D91C-34E6-4E60-BEEB-0B9327AA4C36}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/17 - Generics/Generics/Generics/Constraints.cs b/17 - Generics/Generics/Generics/Constraints.cs new file mode 100644 index 0000000..ec42370 --- /dev/null +++ b/17 - Generics/Generics/Generics/Constraints.cs @@ -0,0 +1,46 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace Generics +{ + public interface IAddable + { + void Add(); + } + + public sealed class A { } + + public class Container + where T: class, IConvertible, new() + where K: struct + { + public Container() + { + T t = new T(); + int i = t.ToInt32(null); + K k = new K(); + } + + + } + + public class Utils2 + { + public static T GetBiggest(T t1, T t2) where T : IComparable + { + return t1.CompareTo(t2) > 0 ? t1 : t2; + } + + public static void Compare() + { + string s = string.Format("Out of 1 and 2, {0} is bigger", GetBiggest(1, 2)); + Console.WriteLine(s); + } + } + +} diff --git a/17 - Generics/Generics/Generics/Delegate.cs b/17 - Generics/Generics/Generics/Delegate.cs new file mode 100644 index 0000000..01ae52a --- /dev/null +++ b/17 - Generics/Generics/Generics/Delegate.cs @@ -0,0 +1,47 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace Generics3 +{ + public class GenericClass + { + public delegate T GenericDelegate(int i); + + public void UseDelegate(GenericDelegate del) {} + } + + public class NonGeneric + { + public delegate T GenericDelegate1(int i) where T : class; + public delegate U GenericDelegate2(V v); + + public void UseDelegate(GenericDelegate1 del) where T : class { } + } + + public class GenericDelegateUser + { + string StandardMethod(int i) { return ""; } + + public void UseGenericDelegates() + { + GenericClass gcs = new GenericClass(); + + //generic method can be called used explicitly like this + GenericClass.GenericDelegate del = new GenericClass.GenericDelegate(StandardMethod); + gcs.UseDelegate(del); + + //or implicity like this + gcs.UseDelegate(StandardMethod); + + //Implicit use of generic delegate + NonGeneric ng = new NonGeneric(); + ng.UseDelegate(StandardMethod); + } + } + +} diff --git a/17 - Generics/Generics/Generics/GenericAsBase.cs b/17 - Generics/Generics/Generics/GenericAsBase.cs new file mode 100644 index 0000000..f585878 --- /dev/null +++ b/17 - Generics/Generics/Generics/GenericAsBase.cs @@ -0,0 +1,30 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace Generics +{ + //public class GenericAsBase : T {} + + //base + public class BaseClass { } + //first tier + public class DerivedGenericClass: BaseClass {} + //second tier + public class DerivedClass: DerivedGenericClass {} + public class SecondDerivedGenericClass : DerivedGenericClass { } + + //constrainst repeated in derived generic class + public class GenericBase where T : new() {} + public class GenericDerived : GenericBase where T : new() { } + + //type arguments + public class Map { } + public class StringMap : Map { } + public class StringToIntMap : StringMap { } + public class StringToDoubleMap : Map { } +} diff --git a/17 - Generics/Generics/Generics/GenericEvents.cs b/17 - Generics/Generics/Generics/GenericEvents.cs new file mode 100644 index 0000000..8bda88c --- /dev/null +++ b/17 - Generics/Generics/Generics/GenericEvents.cs @@ -0,0 +1,40 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace Generics +{ + //generic delegate that takes sender and event args type paramters + public delegate void StandaloneGenericDelegate(S sender, A args); + + + public class TimedEventArgs: EventArgs + { + //constructor + public TimedEventArgs(DateTime time) { _timeOfEvent = time; } + + //member variable + DateTime _timeOfEvent; + + //property + public DateTime TimeOfEvent { get{ return _timeOfEvent; }} + + } + + public class TimedEventRaiser + { + public event StandaloneGenericDelegate TimedEvent; + + public void Raiser() + { + if (TimedEvent != null) + { + TimedEvent(this, new TimedEventArgs(DateTime.Now)); + } + } + } +} diff --git a/17 - Generics/Generics/Generics/GenericMethod.cs b/17 - Generics/Generics/Generics/GenericMethod.cs new file mode 100644 index 0000000..ad57819 --- /dev/null +++ b/17 - Generics/Generics/Generics/GenericMethod.cs @@ -0,0 +1,34 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace Generics +{ + public class Utils + { + Random _random = new Random(); + + public T ReturnRandomElementOfArray(T[] coll) + { + return coll[_random.Next(coll.Length - 1)]; + } + + public int ReturnRandomElementOfArray(int[] coll) + { + return coll[_random.Next(coll.Length - 1)]; + } + + public static void UtilCaller() + { + Utils u = new Utils(); + double[] dblColl = new double[]{1.0, 2.0, 3.0}; + int[] intColl = new int[]{4, 5, 6}; + double dblRandom = u.ReturnRandomElementOfArray(dblColl); //type argument specified + int intRandom = u.ReturnRandomElementOfArray(intColl); //type argument infered + } + } +} diff --git a/17 - Generics/Generics/Generics/GenericVirtualMethods.cs b/17 - Generics/Generics/Generics/GenericVirtualMethods.cs new file mode 100644 index 0000000..b76eb27 --- /dev/null +++ b/17 - Generics/Generics/Generics/GenericVirtualMethods.cs @@ -0,0 +1,31 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace Generics2 +{ + //generic base class with a generic method + public class GenericBase + { + public virtual void MyMethodUsingGenericParameter(T t) { } + public virtual void MyGenericMethod(W w) where W: IComparable{ } + } + + //derived generic class + public class GenericInherited: GenericBase + { + public override void MyMethodUsingGenericParameter(V v) { } + public override void MyGenericMethod(W w) { w.CompareTo(null); } + } + + //non-generic class + public class NonGenericInherited : GenericInherited + { + public override void MyMethodUsingGenericParameter(int i) { } + public override void MyGenericMethod(W w) {} + } +} diff --git a/17 - Generics/Generics/Generics/Generics.csproj b/17 - Generics/Generics/Generics/Generics.csproj new file mode 100644 index 0000000..a969bba --- /dev/null +++ b/17 - Generics/Generics/Generics/Generics.csproj @@ -0,0 +1,65 @@ + + + Debug + AnyCPU + 8.0.41202 + 2.0 + {B2A4D91C-34E6-4E60-BEEB-0B9327AA4C36} + Exe + Generics + Generics + 4 + + + true + full + false + .\bin\Debug\ + DEBUG;TRACE + + + false + true + .\bin\Release\ + TRACE + + + + + + + + + + + + + + + + + + + + + + ResXFileCodeGenerator + Resources.cs + + + True + Resources.resx + + + True + Settings.settings + + + + SettingsSingleFileGenerator + Settings.cs + + + + + \ No newline at end of file diff --git a/17 - Generics/Generics/Generics/GrowableArray.cs b/17 - Generics/Generics/Generics/GrowableArray.cs new file mode 100644 index 0000000..ca1695a --- /dev/null +++ b/17 - Generics/Generics/Generics/GrowableArray.cs @@ -0,0 +1,34 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +public class GrowableArray +{ + private object[] _collection = new object[16]; + private int _count = 0; + + public void AddElement(object element) + { + if (_count >= _collection.Length) + { + object[] temp = new object[_collection.Length * 2]; + Array.Copy(_collection, temp, _collection.Length); + _collection = temp; + } + _collection[_count] = element; + ++_count; + } + + public object GetElement(int elementNumber) + { + if (elementNumber >= _count) + { + throw new IndexOutOfRangeException(); + } + return _collection[elementNumber]; + } +} diff --git a/17 - Generics/Generics/Generics/GrowableArrayGeneric.cs b/17 - Generics/Generics/Generics/GrowableArrayGeneric.cs new file mode 100644 index 0000000..680b35d --- /dev/null +++ b/17 - Generics/Generics/Generics/GrowableArrayGeneric.cs @@ -0,0 +1,34 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +public class GrowableArray +{ + private T[] _collection = new T[16]; + private int _count = 0; + + public void AddElement(T element) + { + if (_count >= _collection.Length) + { + T[] temp = new T[_collection.Length * 2]; + Array.Copy(_collection, temp, _collection.Length); + _collection = temp; + } + _collection[_count] = element; + ++_count; + } + + public T GetElement(int elementNumber) + { + if (elementNumber >= _count) + { + throw new IndexOutOfRangeException(); + } + return _collection[elementNumber]; + } +} diff --git a/17 - Generics/Generics/Generics/GrowableArrayGenericUser.cs b/17 - Generics/Generics/Generics/GrowableArrayGenericUser.cs new file mode 100644 index 0000000..c712ff7 --- /dev/null +++ b/17 - Generics/Generics/Generics/GrowableArrayGenericUser.cs @@ -0,0 +1,46 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace Generics +{ + public class GrowableArrayGenericUser + { + public GrowableArrayGenericUser() + { + GrowableArray ga = new GrowableArray(); + int num = 10; + ga.AddElement(num); //no boxing operation here + int newNum = (int)ga.GetElement(0); //type safety and no unboxing operation + // string str = (string)ga.GetElement(0); //would not compile + } + + public void MethodOne(GrowableArray gad) + { + ; + } + + public void MethodTwo(GrowableArray gad) + { + ; + } + + static void main() + { + GrowableArray ga = new GrowableArray(); + //MethodOne(ga); //wil NOT compile + //MethodTwo(ga); //wil NOT compile + } + + static void main2() + { + GrowableArray ga = new GrowableArray(); + int i = 7; + ga.AddElement(i); + } + } +} diff --git a/17 - Generics/Generics/Generics/GrowableArrayUser.cs b/17 - Generics/Generics/Generics/GrowableArrayUser.cs new file mode 100644 index 0000000..0cc0fad --- /dev/null +++ b/17 - Generics/Generics/Generics/GrowableArrayUser.cs @@ -0,0 +1,22 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace Generics +{ + public class GrowableArrayUser + { + public GrowableArrayUser() + { + GrowableArray ga = new GrowableArray(); + int num = 10; + ga.AddElement(num); //boxing operation here + int newNum = (int)ga.GetElement(0); //no type safety and unboxing operation + string str = (string)ga.GetElement(0); //runtime error here + } + } +} diff --git a/17 - Generics/Generics/Generics/Interfaces.cs b/17 - Generics/Generics/Generics/Interfaces.cs new file mode 100644 index 0000000..1e8546d --- /dev/null +++ b/17 - Generics/Generics/Generics/Interfaces.cs @@ -0,0 +1,35 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace Generics +{ + public interface IGeneric + { + T InterfaceMethod(); + } + + public class GenericInterfaceImplementor: IGeneric + { + public T InterfaceMethod() { return default(T);} + } + + public class InterfaceImplementor: IGeneric + { + public int InterfaceMethod() { return 0; } + } + + /* compile error CS0111: Type 'DerivedInterfaceImplementor' already defines a member called + 'InterfaceMethod' with the same parameter types + + public class DerivedInterfaceImplementor : InterfaceImplementor, IGeneric + { + public int InterfaceMethod() { return 0; } + public double InterfaceMethod() { return 0.0; } + } + */ +} \ No newline at end of file diff --git a/17 - Generics/Generics/Generics/Program.cs b/17 - Generics/Generics/Generics/Program.cs new file mode 100644 index 0000000..84877e2 --- /dev/null +++ b/17 - Generics/Generics/Generics/Program.cs @@ -0,0 +1,20 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace Generics +{ + class Program + { + static void Main(string[] args) + { + Generics2.NonGenericInherited i = new Generics2.NonGenericInherited(); + Reflection r = new Reflection(); + Console.ReadLine(); + } + } +} diff --git a/17 - Generics/Generics/Generics/Properties/AssemblyInfo.cs b/17 - Generics/Generics/Generics/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0beba7c --- /dev/null +++ b/17 - Generics/Generics/Generics/Properties/AssemblyInfo.cs @@ -0,0 +1,29 @@ +#region Using directives + +using System.Reflection; +using System.Runtime.CompilerServices; + +#endregion + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Generics")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany(".")] +[assembly: AssemblyProduct("Generics")] +[assembly: AssemblyCopyright("Copyright @ . 2004")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.*")] diff --git a/17 - Generics/Generics/Generics/Properties/Resources.cs b/17 - Generics/Generics/Generics/Properties/Resources.cs new file mode 100644 index 0000000..d88b3c8 --- /dev/null +++ b/17 - Generics/Generics/Generics/Properties/Resources.cs @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.40607.42 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Generics.Properties +{ + using System; + using System.IO; + using System.Resources; + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the Strongly Typed Resource Builder + // class via a tool like ResGen or Visual Studio.NET. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + class Resources + { + + private static System.Resources.ResourceManager _resMgr; + + private static System.Globalization.CultureInfo _resCulture; + + /*FamANDAssem*/ + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Resources.ResourceManager ResourceManager + { + get + { + if ((_resMgr == null)) + { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Resources", typeof(Resources).Assembly); + _resMgr = temp; + } + return _resMgr; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Globalization.CultureInfo Culture + { + get + { + return _resCulture; + } + set + { + _resCulture = value; + } + } + } +} diff --git a/17 - Generics/Generics/Generics/Properties/Resources.resx b/17 - Generics/Generics/Generics/Properties/Resources.resx new file mode 100644 index 0000000..3e18af9 --- /dev/null +++ b/17 - Generics/Generics/Generics/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/17 - Generics/Generics/Generics/Properties/Settings.cs b/17 - Generics/Generics/Generics/Properties/Settings.cs new file mode 100644 index 0000000..bdb4faa --- /dev/null +++ b/17 - Generics/Generics/Generics/Properties/Settings.cs @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.40607.42 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Generics.Properties +{ + public partial class Settings : System.Configuration.ApplicationSettingsBase + { + private static Settings m_Value; + + private static object m_SyncObject = new object(); + + public static Settings Value + { + get + { + if ((Settings.m_Value == null)) + { + System.Threading.Monitor.Enter(Settings.m_SyncObject); + if ((Settings.m_Value == null)) + { + try + { + Settings.m_Value = new Settings(); + } + finally + { + System.Threading.Monitor.Exit(Settings.m_SyncObject); + } + } + } + return Settings.m_Value; + } + } + } +} diff --git a/17 - Generics/Generics/Generics/Properties/Settings.settings b/17 - Generics/Generics/Generics/Properties/Settings.settings new file mode 100644 index 0000000..4024694 --- /dev/null +++ b/17 - Generics/Generics/Generics/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/17 - Generics/Generics/Generics/Reflection.cs b/17 - Generics/Generics/Generics/Reflection.cs new file mode 100644 index 0000000..0a94ca3 --- /dev/null +++ b/17 - Generics/Generics/Generics/Reflection.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Generics +{ + class MyGenericClass { } + + class Reflection + { + public Reflection() + { + List l = new List(); + bool b1 = l.GetType().IsGenericTypeDefinition; + bool b2 = l.GetType().GetGenericTypeDefinition().IsGenericTypeDefinition; + + DumpGenericTypeParams(typeof(MyGenericClass).GetGenericTypeDefinition()); + } + + static void DumpGenericTypeParams(Type t) + { + if (t.IsGenericTypeDefinition) + { + foreach (Type genericType in t.GetGenericArguments()) + { + Console.WriteLine(genericType.Name); + } + } + } + } +} diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/ByteStreamer.cs b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/ByteStreamer.cs new file mode 100644 index 0000000..101cdfb --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/ByteStreamer.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace Chapter_18_indexers +{ + class ByteStreamer + { + string m_filename; + public ByteStreamer(string filename) + { + m_filename = filename; + } + public IEnumerator GetEnumerator() + { + using (FileStream stream = File.Open(m_filename, FileMode.Open)) + { + yield return (byte) stream.ReadByte(); + } + } + } +} diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.csproj b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.csproj new file mode 100644 index 0000000..7079789 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.csproj @@ -0,0 +1,61 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {2C6A98C6-AF52-4DD3-B620-51EB9779F206} + Exe + Properties + Chapter_18_indexers + Chapter 18 indexers + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.csproj.user b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.csproj.user new file mode 100644 index 0000000..ace9a86 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.csproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.sln b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.sln new file mode 100644 index 0000000..ee74808 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C# Express 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Chapter 18 indexers", "Chapter 18 indexers.csproj", "{2C6A98C6-AF52-4DD3-B620-51EB9779F206}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2C6A98C6-AF52-4DD3-B620-51EB9779F206}.Debug|x86.ActiveCfg = Debug|x86 + {2C6A98C6-AF52-4DD3-B620-51EB9779F206}.Debug|x86.Build.0 = Debug|x86 + {2C6A98C6-AF52-4DD3-B620-51EB9779F206}.Release|x86.ActiveCfg = Release|x86 + {2C6A98C6-AF52-4DD3-B620-51EB9779F206}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.suo b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.suo new file mode 100644 index 0000000..4f3c9a5 Binary files /dev/null and b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Chapter 18 indexers.suo differ diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/IntList.cs b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/IntList.cs new file mode 100644 index 0000000..2a6f8ba --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/IntList.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_18_indexers +{ +public class IntList: IEnumerable +{ + int m_count = 0; + int[] m_values; + public IntList(int capacity) + { + m_values = new int[capacity]; + } + public void Add(int value) + { + m_values[m_count] = value; + m_count++; + } + public int this[int index] + { + get { return m_values[index]; } + set { m_values[index] = value; } + } + public int Count { get { return m_count; } } + public IEnumerator GetEnumerator() + { + return new IntListEnumerator(this); + } + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } +} +public class IntListEnumerator : IEnumerator +{ + IntList m_intList; + int m_index; + internal IntListEnumerator(IntList intList) + { + m_intList = intList; + Reset(); + } + public bool MoveNext() + { + m_index++; + return m_index < m_intList.Count; + } + public int Current + { + get { return (m_intList[m_index]); } + } + object IEnumerator.Current + { + get { return Current; } + } + void IDisposable.Dispose() + { + } + public void Reset() + { + m_index = -1; + } +} +} diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/IntListNew.cs b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/IntListNew.cs new file mode 100644 index 0000000..7f512da --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/IntListNew.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_18_indexers +{ +public class IntListNew: IEnumerable +{ + int m_count = 0; + int[] m_values; + public IntListNew(int capacity) + { + m_values = new int[capacity]; + } + public void Add(int value) + { + m_values[m_count] = value; + m_count++; + } + public int this[int index] + { + get { return m_values[index]; } + set { m_values[index] = value; } + } + public int Count { get { return m_count; } } + public IEnumerator GetEnumerator() + { + for (int index = 0; index < m_count; index++) + { + yield return m_values[index]; + } + } +public IEnumerable ReversedItems() +{ + for (int index = m_count - 1; index >= 0; index--) + { + yield return m_values[index]; + } +} +} +} \ No newline at end of file diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/MyListNew.cs b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/MyListNew.cs new file mode 100644 index 0000000..704fa15 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/MyListNew.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_18_indexers +{ +public class MyListNew : IEnumerable +{ + int m_count = 0; + T[] m_values; + public MyListNew(int capacity) + { + m_values = new T[capacity]; + } + public void Add(T value) + { + m_values[m_count] = value; + m_count++; + } + public T this[int index] + { + get { return m_values[index]; } + set { m_values[index] = value; } + } + public int Count { get { return m_count; } } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + public IEnumerator GetEnumerator() + { + for (int index = 0; index < m_count; index++) + { + yield return m_values[index]; + } + } + public IEnumerable ReversedItems() + { + for (int index = m_count - 1; index >= 0; index--) + { + yield return m_values[index]; + } + } +} +} diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Program.cs b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Program.cs new file mode 100644 index 0000000..1cff811 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Program.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Chapter_18_indexers +{ + class Program + { + static void Main(string[] args) + { +IntListNew intList = new IntListNew(3); +intList.Add(1); +intList.Add(2); +intList.Add(4); + +foreach (int number in intList.ReversedItems()) +{ + Console.WriteLine(number); +} + +MyListNew myIntList = new MyListNew(5); +myIntList.Add(1); +myIntList.Add(2); +myIntList.Add(4); +myIntList.Add(9); +myIntList.Add(16); + +foreach (int number in myIntList.ReversedItems()) +{ + Console.WriteLine(number); +} + } + } +} diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Properties/AssemblyInfo.cs b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b2770f5 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Chapter 18 indexers")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("Chapter 18 indexers")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("33b1e326-29a0-473c-902e-fceb2239936d")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/bin/Debug/Chapter 18 indexers.vshost.exe b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/bin/Debug/Chapter 18 indexers.vshost.exe new file mode 100644 index 0000000..bb84a51 Binary files /dev/null and b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/bin/Debug/Chapter 18 indexers.vshost.exe differ diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/bin/Release/Chapter 18 indexers.exe b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/bin/Release/Chapter 18 indexers.exe new file mode 100644 index 0000000..1135013 Binary files /dev/null and b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/bin/Release/Chapter 18 indexers.exe differ diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/bin/Release/Chapter 18 indexers.pdb b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/bin/Release/Chapter 18 indexers.pdb new file mode 100644 index 0000000..c1a4136 Binary files /dev/null and b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/bin/Release/Chapter 18 indexers.pdb differ diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Debug/Chapter 18 indexers.csproj.FileListAbsolute.txt b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Debug/Chapter 18 indexers.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..f3d7ae7 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Debug/Chapter 18 indexers.csproj.FileListAbsolute.txt @@ -0,0 +1 @@ +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 18 indexers\obj\x86\Debug\ResolveAssemblyReference.cache diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..1c4b3a5 Binary files /dev/null and b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/Chapter 18 indexers.csproj.FileListAbsolute.txt b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/Chapter 18 indexers.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..e292260 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/Chapter 18 indexers.csproj.FileListAbsolute.txt @@ -0,0 +1,5 @@ +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 18 indexers\obj\x86\Release\ResolveAssemblyReference.cache +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 18 indexers\bin\Release\Chapter 18 indexers.exe +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 18 indexers\bin\Release\Chapter 18 indexers.pdb +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 18 indexers\obj\x86\Release\Chapter 18 indexers.exe +C:\Users\Eric Gunnerson\AppData\Local\Temporary Projects\Chapter 18 indexers\obj\x86\Release\Chapter 18 indexers.pdb diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/Chapter 18 indexers.exe b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/Chapter 18 indexers.exe new file mode 100644 index 0000000..1135013 Binary files /dev/null and b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/Chapter 18 indexers.exe differ diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/Chapter 18 indexers.pdb b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/Chapter 18 indexers.pdb new file mode 100644 index 0000000..c1a4136 Binary files /dev/null and b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/Chapter 18 indexers.pdb differ diff --git a/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..99ec1ed Binary files /dev/null and b/18 - Indexers, Enumerators and Iterators/Chapter 18 indexers/obj/x86/Release/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/18 - Indexers, Enumerators and Iterators/Enumerators and Foreach/Build1.bat b/18 - Indexers, Enumerators and Iterators/Enumerators and Foreach/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Enumerators and Foreach/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/18 - Indexers, Enumerators and Iterators/Enumerators and Foreach/File_1.cs b/18 - Indexers, Enumerators and Iterators/Enumerators and Foreach/File_1.cs new file mode 100644 index 0000000..e85ecb9 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Enumerators and Foreach/File_1.cs @@ -0,0 +1,133 @@ +// 19 - Indexers and Enumerators\Enumerators and Foreach +// copyright 2000 Eric Gunnerson +using System; +using System.Collections; + +// Note: This class is not thread-safe +public class IntList: IEnumerable +{ + int[] values = new int[10]; + int allocated = 10; + int count = 0; + int revision = 0; + + public void Add(int value) + { + // reallocate if necessary + if (count + 1 == allocated) + { + int[] newValues = new int[allocated * 2]; + for (int index = 0; index < count; index++) + { + newValues[index] = values[index]; + } + allocated *= 2; + } + values[count] = value; + count++; + revision++; + } + + public int Count + { + get + { + return(count); + } + } + + void CheckIndex(int index) + { + if (index >= count) + throw new ArgumentOutOfRangeException("Index value out of range"); + } + + public int this[int index] + { + get + { + CheckIndex(index); + return(values[index]); + } + set + { + CheckIndex(index); + values[index] = value; + revision++; + } + } + + public IEnumerator GetEnumerator() + { + return(new IntListEnumerator(this)); + } + + internal int Revision + { + get + { + return(revision); + } + } +} + +class IntListEnumerator: IEnumerator +{ + IntList intList; + int revision; + int index; + + internal IntListEnumerator(IntList intList) + { + this.intList = intList; + Reset(); + } + + public bool MoveNext() + { + index++; + if (index >= intList.Count) + return(false); + else + return(true); + } + + public object Current + { + get + { + if (revision != intList.Revision) + throw new InvalidOperationException("Collection modified while enumerating."); + return(intList[index]); + } + } + + public void Reset() + { + index = -1; + revision = intList.Revision; + } +} + +class Test +{ + public static void Main() + { + IntList list = new IntList(); + + list.Add(1); + list.Add(55); + list.Add(43); + + foreach (int value in list) + { + Console.WriteLine("Value = {0}", value); + } + + foreach (int value in list) + { + Console.WriteLine("Value = {0}", value); + list.Add(124); + } + } +} \ No newline at end of file diff --git a/18 - Indexers, Enumerators and Iterators/Indexing with Multiple Parameters/Build1.bat b/18 - Indexers, Enumerators and Iterators/Indexing with Multiple Parameters/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Indexing with Multiple Parameters/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/18 - Indexers, Enumerators and Iterators/Indexing with Multiple Parameters/File_1.cs b/18 - Indexers, Enumerators and Iterators/Indexing with Multiple Parameters/File_1.cs new file mode 100644 index 0000000..a464a9c --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Indexing with Multiple Parameters/File_1.cs @@ -0,0 +1,73 @@ +// 19 - Indexers and Enumerators\Indexing with Multiple Parameters +// copyright 2000 Eric Gunnerson +using System; + +public class Player +{ + string name; + + public Player(string name) + { + this.name = name; + } + + public override string ToString() + { + return(name); + } +} + +public class Board +{ + Player[,] board = new Player[8, 8]; + + int RowToIndex(string row) + { + string temp = row.ToUpper(); + return((int) temp[0] - (int) 'A'); + } + + int PositionToColumn(string pos) + { + return(pos[1] - '0' - 1); + } + + public Player this[string row, int column] + { + get + { + return(board[RowToIndex(row), column - 1]); + } + set + { + board[RowToIndex(row), column - 1] = value; + } + } + + public Player this[string position] + { + get + { + return(board[RowToIndex(position), + PositionToColumn(position)]); + } + set + { + board[RowToIndex(position), + PositionToColumn(position)] = value; + } + } +} +class Test +{ + public static void Main() + { + Board board = new Board(); + + board["A", 4] = new Player("White King"); + board["H", 4] = new Player("Black King"); + + Console.WriteLine("A4 = {0}", board["A", 4]); + Console.WriteLine("H4 = {0}", board["H4"]); + } +} \ No newline at end of file diff --git a/18 - Indexers, Enumerators and Iterators/Indexing with an Integer Index/Build1.bat b/18 - Indexers, Enumerators and Iterators/Indexing with an Integer Index/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Indexing with an Integer Index/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/18 - Indexers, Enumerators and Iterators/Indexing with an Integer Index/File_1.cs b/18 - Indexers, Enumerators and Iterators/Indexing with an Integer Index/File_1.cs new file mode 100644 index 0000000..da82d4c --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Indexing with an Integer Index/File_1.cs @@ -0,0 +1,75 @@ +// 19 - Indexers and Enumerators\Indexing with an Integer Index +// copyright 2000 Eric Gunnerson +using System; +using System.Collections; +class DataValue +{ + public DataValue(string name, object data) + { + this.name = name; + this.data = data; + } + public string Name + { + get + { + return(name); + } + set + { + name = value; + } + } + public object Data + { + get + { + return(data); + } + set + { + data = value; + } + } + string name; + object data; +} +class DataRow +{ + public DataRow() + { + row = new ArrayList(); + } + + public void Load() + { + /* load code here */ + row.Add(new DataValue("Id", 5551212)); + row.Add(new DataValue("Name", "Fred")); + row.Add(new DataValue("Salary", 2355.23m)); + } + + // the indexer + public DataValue this[int column] + { + get + { + return((DataValue) row[column - 1]); + } + set + { + row[column - 1] = value; + } + } + ArrayList row; +} +class Test +{ + public static void Main() + { + DataRow row = new DataRow(); + row.Load(); + Console.WriteLine("Column 0: {0}", row[1].Data); + row[1].Data = 12; // set the ID + } +} \ No newline at end of file diff --git a/18 - Indexers, Enumerators and Iterators/Indexing with an String Index/Build1.bat b/18 - Indexers, Enumerators and Iterators/Indexing with an String Index/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Indexing with an String Index/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/18 - Indexers, Enumerators and Iterators/Indexing with an String Index/File_1.cs b/18 - Indexers, Enumerators and Iterators/Indexing with an String Index/File_1.cs new file mode 100644 index 0000000..9745607 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Indexing with an String Index/File_1.cs @@ -0,0 +1,98 @@ +// 19 - Indexers and Enumerators\Indexing with an String Index +// copyright 2000 Eric Gunnerson +using System; +using System.Collections; +class DataValue +{ + public DataValue(string name, object data) + { + this.name = name; + this.data = data; + } + public string Name + { + get + { + return(name); + } + set + { + name = value; + } + } + public object Data + { + get + { + return(data); + } + set + { + data = value; + } + } + string name; + object data; +} +class DataRow +{ + public DataRow() + { + row = new ArrayList(); + } + + public void Load() + { + /* load code here */ + row.Add(new DataValue("Id", 5551212)); + row.Add(new DataValue("Name", "Fred")); + row.Add(new DataValue("Salary", 2355.23m)); + } + + public DataValue this[int column] + { + get + { + return( (DataValue) row[column - 1]); + } + set + { + row[column - 1] = value; + } + } + int FindColumn(string name) + { + for (int index = 0; index < row.Count; index++) + { + DataValue dataValue = (DataValue) row[index]; + if (dataValue.Name == name) + return(index); + } + return(-1); + } + public DataValue this[string name] + { + get + { + return( (DataValue) this[FindColumn(name)]); + } + set + { + this[FindColumn(name)] = value; + } + } + ArrayList row; +} +class Test +{ + public static void Main() + { + DataRow row = new DataRow(); + row.Load(); + DataValue val = row["Id"]; + Console.WriteLine("Id: {0}", val.Data); + Console.WriteLine("Salary: {0}", row["Salary"].Data); + row["Name"].Data = "Barney"; // set the name + Console.WriteLine("Name: {0}", row["Name"].Data); + } +} \ No newline at end of file diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators.sln b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators.sln new file mode 100644 index 0000000..8cabe3f --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Iterators", "Iterators\Iterators.csproj", "{62E2FF0A-4101-47A2-9DF4-D3F285526477}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {62E2FF0A-4101-47A2-9DF4-D3F285526477}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {62E2FF0A-4101-47A2-9DF4-D3F285526477}.Debug|Any CPU.Build.0 = Debug|Any CPU + {62E2FF0A-4101-47A2-9DF4-D3F285526477}.Release|Any CPU.ActiveCfg = Release|Any CPU + {62E2FF0A-4101-47A2-9DF4-D3F285526477}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/GenericCollection.cs b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/GenericCollection.cs new file mode 100644 index 0000000..9dd46a9 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/GenericCollection.cs @@ -0,0 +1,97 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +// Note: This class is not thread-safe +public class GenericList : IEnumerable +{ + T[] values = new T[10]; + int allocated = 10; + int count = 0; + int revision = 0; + public void Add(T value) + { +// reallocate if necessary... + if (count + 1 == allocated) + { + T[] newValues = new T[allocated * 2]; + for (int index = 0; index < count; index++) + { + newValues[index] = values[index]; + } + allocated *= 2; + } + values[count] = value; + count++; + revision++; + } + public int Count + { + get + { + return (count); + } + } + void CheckIndex(int index) + { + if (index >= count) + throw new ArgumentOutOfRangeException("Index value out of range"); + } + public T this[int index] + { + get + { + CheckIndex(index); + return (values[index]); + } + set + { + CheckIndex(index); + values[index] = value; + revision++; + } + } + public IEnumerator GetEnumerator() + { + for (int index = 0; index < count; ++index) + { + yield return values[index]; + } + } + + public IEnumerable BidirectionalSubrange(bool forward, int start, int end) + { + if (start < 0 || end >= count) + { + throw new IndexOutOfRangeException("Start must be zero or greater and end must be less than the size of the collection"); + } + + if (forward) + { + for (int index = start; index < end; ++index) + { + yield return values[index]; + } + } + else + { + for (int index = end; index >= start; --index) + { + yield return values[index]; + } + } + } + + internal int Revision + { + get + { + return (revision); + } + } +} + diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/IntCollection.cs b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/IntCollection.cs new file mode 100644 index 0000000..376b220 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/IntCollection.cs @@ -0,0 +1,90 @@ +#region Using directives + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +#endregion + + +// Note: This class is not thread-safe +public class IntList : IEnumerable +{ + int[] values = new int[10]; + int allocated = 10; + int count = 0; + int revision = 0; + public void Add(int value) + { +// reallocate if necessary... + if (count + 1 == allocated) + { + int[] newValues = new int[allocated * 2]; + for (int index = 0; index < count; index++) + { + newValues[index] = values[index]; + } + allocated *= 2; + } + values[count] = value; + count++; + revision++; + } + public int Count + { + get + { + return (count); + } + } + void CheckIndex(int index) + { + if (index >= count) + throw new ArgumentOutOfRangeException("Index value out of range"); + } + public int this[int index] + { + get + { + CheckIndex(index); + return (values[index]); + } + set + { + CheckIndex(index); + values[index] = value; + revision++; + } + } + public IEnumerator GetEnumerator() + { + for (int index = 0; index < count; ++index) + { + yield return values[index]; + } + } + + public IEnumerable BidirectionalSubrange(bool forward, int start, int end) + { + if (start < 0 || end >= count) + { + throw new IndexOutOfRangeException("Start must be zero or greater and" + + " end must be less than the size of the collection"); + } + + int step = forward == true ? 1 : -1; + for (int index = start; index != end; index += step) + { + yield return values[index]; + } + } + + internal int Revision + { + get + { + return (revision); + } + } +} diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Iterators.csproj b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Iterators.csproj new file mode 100644 index 0000000..7cd4211 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Iterators.csproj @@ -0,0 +1,57 @@ + + + Debug + AnyCPU + 8.0.40607 + 2.0 + {62E2FF0A-4101-47A2-9DF4-D3F285526477} + Exe + Iterators + Iterators + 4 + + + true + full + false + .\bin\Debug\ + DEBUG;TRACE + + + false + true + .\bin\Release\ + TRACE + + + + + + + + + + + + + + + ResXFileCodeGenerator + Resources.cs + + + True + Resources.resx + + + True + Settings.settings + + + SettingsSingleFileGenerator + Settings.cs + + + + + \ No newline at end of file diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/MutliMap.cs b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/MutliMap.cs new file mode 100644 index 0000000..49da419 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/MutliMap.cs @@ -0,0 +1,36 @@ +#region Using directives + +using System; +using System.Collections; +using System.Text; + +#endregion + +public class MutliMap +{ + Hashtable map = new Hashtable(); + + public void Add(object key, object value) + { + if (map[key] == null) + map[key] = new ArrayList(); + + ((ArrayList)map[key]).Add(value); + } + + public IEnumerator KeysAndValues() + { + foreach (object key in map.Keys) + { + yield return key; + if (map[key] != null) + { + ArrayList values = (ArrayList)map[key]; + foreach (object value in values) + { + yield return value; + } + } + } + } +} diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Person.cs b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Person.cs new file mode 100644 index 0000000..6a91f45 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Person.cs @@ -0,0 +1,29 @@ +#region Using directives + +using System; +using System.Collections; +using System.Text; + +#endregion + +public class Person +{ + string firstName; + string middleName; + string lastName; + + public Person(string firstName, string middleName, string lastName) + { + this.firstName = firstName; + this.middleName = middleName; + this.lastName = lastName; + } + + public IEnumerable Names() + { + yield return firstName; + yield return middleName; + yield return lastName; + } +} + diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Program.cs b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Program.cs new file mode 100644 index 0000000..5f8dab0 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Program.cs @@ -0,0 +1,23 @@ +#region Using directives + +using System; +using System.Collections.Generic; +using System.Text; + +#endregion + +namespace Iterators { + class Program { + static void Main(string[] args) + { + IntList il = new IntList(); + il.Add(1); + il.Add(2); + il.Add(3); + il.Add(4); + + foreach (int i in il.BidirectionalSubrange(false, 1, 3)) + Console.WriteLine(i); + } + } +} diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/AssemblyInfo.cs b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ab0c723 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/AssemblyInfo.cs @@ -0,0 +1,29 @@ +#region Using directives + +using System.Reflection; +using System.Runtime.CompilerServices; + +#endregion + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Iterators")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany(".")] +[assembly: AssemblyProduct("Iterators")] +[assembly: AssemblyCopyright("Copyright @ . 2004")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.*")] diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Resources.cs b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Resources.cs new file mode 100644 index 0000000..d75ebf5 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Resources.cs @@ -0,0 +1,67 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.40607.42 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Iterators.Properties { + using System; + using System.IO; + using System.Resources; + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the Strongly Typed Resource Builder + // class via a tool like ResGen or Visual Studio.NET. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + class Resources { + + private static System.Resources.ResourceManager _resMgr; + + private static System.Globalization.CultureInfo _resCulture; + + /*FamANDAssem*/ + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Resources.ResourceManager ResourceManager + { + get + { + if ((_resMgr == null)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("Resources", typeof(Resources).Assembly); + _resMgr = temp; + } + return _resMgr; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + public static System.Globalization.CultureInfo Culture + { + get + { + return _resCulture; + } + set + { + _resCulture = value; + } + } + } +} diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Resources.resx b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Resources.resx new file mode 100644 index 0000000..3e18af9 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Settings.cs b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Settings.cs new file mode 100644 index 0000000..3a31b36 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Settings.cs @@ -0,0 +1,36 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.40607.42 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Iterators.Properties { + public partial class Settings : System.Configuration.ApplicationSettingsBase { + private static Settings m_Value; + + private static object m_SyncObject = new object(); + + public static Settings Value + { + get + { + if ((Settings.m_Value == null)) { + System.Threading.Monitor.Enter(Settings.m_SyncObject); + if ((Settings.m_Value == null)) { + try { + Settings.m_Value = new Settings(); + } + finally { + System.Threading.Monitor.Exit(Settings.m_SyncObject); + } + } + } + return Settings.m_Value; + } + } + } +} diff --git a/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Settings.settings b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Settings.settings new file mode 100644 index 0000000..4024694 --- /dev/null +++ b/18 - Indexers, Enumerators and Iterators/Iterators/Iterators/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/19 - Strings/An Example/Build1.bat b/19 - Strings/An Example/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/19 - Strings/An Example/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/19 - Strings/An Example/File_1.cs b/19 - Strings/An Example/File_1.cs new file mode 100644 index 0000000..60d9a71 --- /dev/null +++ b/19 - Strings/An Example/File_1.cs @@ -0,0 +1,15 @@ +// 17 - Strings\An Example +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + string s = "Oh, I hadn't thought of that"; + char[] separators = new char[] {' ', ','}; + foreach (string sub in s.Split(separators)) + { + Console.WriteLine("Word: {0}", sub); + } + } +} \ No newline at end of file diff --git a/19 - Strings/Build.bat b/19 - Strings/Build.bat new file mode 100644 index 0000000..6b55348 --- /dev/null +++ b/19 - Strings/Build.bat @@ -0,0 +1 @@ +csc File_.cs diff --git a/19 - Strings/File_.cs b/19 - Strings/File_.cs new file mode 100644 index 0000000..34f1cde --- /dev/null +++ b/19 - Strings/File_.cs @@ -0,0 +1,13 @@ +// 17 - Strings +// copyright 2000 Eric Gunnerson +using System; +class Test +{ + public static void Main() + { + string s = "Test String"; + + for (int index = 0; index < s.Length; index++) + Console.WriteLine("Char: {0}", s[index]); + } +} \ No newline at end of file diff --git a/19 - Strings/Regular Expressions/Build1.bat b/19 - Strings/Regular Expressions/Build1.bat new file mode 100644 index 0000000..6d9e0df --- /dev/null +++ b/19 - Strings/Regular Expressions/Build1.bat @@ -0,0 +1 @@ +csc File_1.cs diff --git a/19 - Strings/Regular Expressions/File_1.cs b/19 - Strings/Regular Expressions/File_1.cs new file mode 100644 index 0000000..5769398 --- /dev/null +++ b/19 - Strings/Regular Expressions/File_1.cs @@ -0,0 +1,18 @@ +// 17 - Strings\Regular Expressions +// copyright 2000 Eric Gunnerson +// file: regex.cs +using System; +using System.Text.RegularExpressions; +class Test +{ + public static void Main() + { + string s = "Oh, I hadn't thought of that"; + Regex regex = new Regex(@" |, "); + char[] separators = new char[] {' ', ','}; + foreach (string sub in regex.Split(s)) + { + Console.WriteLine("Word: {0}", sub); + } + } +} \ No newline at end of file diff --git a/19 - Strings/Regular Expressions/More Complex Parsing/Build1.bat b/19 - Strings/Regular Expressions/More Complex Parsing/Build1.bat new file mode 100644 index 0000000..bae19e5 --- /dev/null +++ b/19 - Strings/Regular Expressions/More Complex Parsing/Build1.bat @@ -0,0 +1 @@ +csc logparse.cs diff --git a/19 - Strings/Regular Expressions/More Complex Parsing/logparse.cs b/19 - Strings/Regular Expressions/More Complex Parsing/logparse.cs new file mode 100644 index 0000000..ccac3a3 --- /dev/null +++ b/19 - Strings/Regular Expressions/More Complex Parsing/logparse.cs @@ -0,0 +1,81 @@ +// 17 - Strings\Regular Expressions\More Complex Parsing +// copyright 2000 Eric Gunnerson +// file=logparse.cs +// compile with: csc logparse.cs +using System; +using System.Net; +using System.IO; +using System.Text.RegularExpressions; +using System.Collections; + +class Test +{ + public static void Main(string[] args) + { + if (args.Length == 0) //we need a file to parse + { + Console.WriteLine("No log file specified."); + } + else + ParseLogFile(args[0]); + } + public static void ParseLogFile(string filename) + { + if (!System.IO.File.Exists(filename)) + { + Console.WriteLine ("The file specified does not exist."); + } + else + { + FileStream f = new FileStream(filename, FileMode.Open); + StreamReader stream = new StreamReader(f); + + string line; + line = stream.ReadLine(); // header line + line = stream.ReadLine(); // version line + line = stream.ReadLine(); // Date line + + Regex regexDate= new Regex(@"\:\s(?[^\s]+)\s"); + Match match = regexDate.Match(line); + string date = ""; + if (match.Length != 0) + date = match.Groups["date"].ToString(); + + line = stream.ReadLine(); // Fields line + + Regex regexLine = + new Regex( // match digit or : + @"(?