Skip to content

Commit 7a218b2

Browse files
authored
Change List to MyList (#785)
This sample code creates a list object, which is easily read as discussing the System.Collections.Generic.List class. Contributes to dotnet/docs#7884
1 parent 865e607 commit 7a218b2

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

snippets/csharp/tour/classes-and-objects/ListBasedExamples.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace ListExamples
22
{
33
using System;
4-
public class List<T>
4+
public class MyList<T>
55
{
66
// Constant
77
const int defaultCapacity = 4;
@@ -11,7 +11,7 @@ public class List<T>
1111
int count;
1212

1313
// Constructor
14-
public List(int capacity = defaultCapacity)
14+
public MyList(int capacity = defaultCapacity)
1515
{
1616
items = new T[capacity];
1717
}
@@ -60,9 +60,9 @@ protected virtual void OnChanged() =>
6060
Changed?.Invoke(this, EventArgs.Empty);
6161

6262
public override bool Equals(object other) =>
63-
Equals(this, other as List<T>);
63+
Equals(this, other as MyList<T>);
6464

65-
static bool Equals(List<T> a, List<T> b)
65+
static bool Equals(MyList<T> a, MyList<T> b)
6666
{
6767
if (Object.ReferenceEquals(a, null)) return Object.ReferenceEquals(b, null);
6868
if (Object.ReferenceEquals(b, null) || a.count != b.count)
@@ -81,32 +81,32 @@ static bool Equals(List<T> a, List<T> b)
8181
public event EventHandler Changed;
8282

8383
// Operators
84-
public static bool operator ==(List<T> a, List<T> b) =>
84+
public static bool operator ==(MyList<T> a, MyList<T> b) =>
8585
Equals(a, b);
8686

87-
public static bool operator !=(List<T> a, List<T> b) =>
87+
public static bool operator !=(MyList<T> a, MyList<T> b) =>
8888
!Equals(a, b);
8989
}
9090

9191
public class ExampleCode
9292
{
9393
public static void ListExampleOne()
9494
{
95-
List<string> list1 = new List<string>();
96-
List<string> list2 = new List<string>(10);
95+
MyList<string> list1 = new MyList<string>();
96+
MyList<string> list2 = new MyList<string>(10);
9797
}
9898

9999
public static void ListExampleTwo()
100100
{
101-
List<string> names = new List<string>();
101+
MyList<string> names = new MyList<string>();
102102
names.Capacity = 100; // Invokes set accessor
103103
int i = names.Count; // Invokes get accessor
104104
int j = names.Capacity; // Invokes get accessor
105105
}
106106

107107
public static void ListExampleThree()
108108
{
109-
List<string> names = new List<string>();
109+
MyList<string> names = new MyList<string>();
110110
names.Add("Liz");
111111
names.Add("Martha");
112112
names.Add("Beth");
@@ -118,10 +118,10 @@ public static void ListExampleThree()
118118
}
119119
public static void ListExampleFour()
120120
{
121-
List<int> a = new List<int>();
121+
MyList<int> a = new MyList<int>();
122122
a.Add(1);
123123
a.Add(2);
124-
List<int> b = new List<int>();
124+
MyList<int> b = new MyList<int>();
125125
b.Add(1);
126126
b.Add(2);
127127
Console.WriteLine(a == b); // Outputs "True"
@@ -138,7 +138,7 @@ static void ListChanged(object sender, EventArgs e)
138138
}
139139
public static void Usage()
140140
{
141-
List<string> names = new List<string>();
141+
MyList<string> names = new MyList<string>();
142142
names.Changed += new EventHandler(ListChanged);
143143
names.Add("Liz");
144144
names.Add("Martha");

0 commit comments

Comments
 (0)