diff --git a/snippets/csharp/tour/classes-and-objects/ListBasedExamples.cs b/snippets/csharp/tour/classes-and-objects/ListBasedExamples.cs index 0e72ae7d2b9..3a58bec5a75 100644 --- a/snippets/csharp/tour/classes-and-objects/ListBasedExamples.cs +++ b/snippets/csharp/tour/classes-and-objects/ListBasedExamples.cs @@ -1,7 +1,7 @@ namespace ListExamples { using System; - public class List + public class MyList { // Constant const int defaultCapacity = 4; @@ -11,7 +11,7 @@ public class List int count; // Constructor - public List(int capacity = defaultCapacity) + public MyList(int capacity = defaultCapacity) { items = new T[capacity]; } @@ -60,9 +60,9 @@ protected virtual void OnChanged() => Changed?.Invoke(this, EventArgs.Empty); public override bool Equals(object other) => - Equals(this, other as List); + Equals(this, other as MyList); - static bool Equals(List a, List b) + static bool Equals(MyList a, MyList b) { if (Object.ReferenceEquals(a, null)) return Object.ReferenceEquals(b, null); if (Object.ReferenceEquals(b, null) || a.count != b.count) @@ -81,10 +81,10 @@ static bool Equals(List a, List b) public event EventHandler Changed; // Operators - public static bool operator ==(List a, List b) => + public static bool operator ==(MyList a, MyList b) => Equals(a, b); - public static bool operator !=(List a, List b) => + public static bool operator !=(MyList a, MyList b) => !Equals(a, b); } @@ -92,13 +92,13 @@ public class ExampleCode { public static void ListExampleOne() { - List list1 = new List(); - List list2 = new List(10); + MyList list1 = new MyList(); + MyList list2 = new MyList(10); } public static void ListExampleTwo() { - List names = new List(); + MyList names = new MyList(); names.Capacity = 100; // Invokes set accessor int i = names.Count; // Invokes get accessor int j = names.Capacity; // Invokes get accessor @@ -106,7 +106,7 @@ public static void ListExampleTwo() public static void ListExampleThree() { - List names = new List(); + MyList names = new MyList(); names.Add("Liz"); names.Add("Martha"); names.Add("Beth"); @@ -118,10 +118,10 @@ public static void ListExampleThree() } public static void ListExampleFour() { - List a = new List(); + MyList a = new MyList(); a.Add(1); a.Add(2); - List b = new List(); + MyList b = new MyList(); b.Add(1); b.Add(2); Console.WriteLine(a == b); // Outputs "True" @@ -138,7 +138,7 @@ static void ListChanged(object sender, EventArgs e) } public static void Usage() { - List names = new List(); + MyList names = new MyList(); names.Changed += new EventHandler(ListChanged); names.Add("Liz"); names.Add("Martha");