110,534
社区成员
发帖
与我相关
我的任务
分享
int[] a1 = new int[] { 1, 2, 3, 4, 5 };
string[] a2 = new string[] { "a", "b", "c", "d", "efg" };
object[] a3 = new object[] { 1, "a", 3.2f, typeof(Program) };
object[] a4 = null;
object[] a5 = new object[] { };
object[] a6 = new object[2];
class Program
{
static void Main(string[] args)
{
A a = new A() { 1, 2, 3 };
}
}
class A : IEnumerable
{
public void Add(int i) { Console.WriteLine(i); }
public IEnumerator GetEnumerator()
{
throw new NotImplementedException();
}
}
a.Add(1);
a.Add(2);
a.Add(3);
List<int> data = new List<int>() { 7, 3, 2, 5, 6, 4, 10, 9, 1, 8 };
data.RemoveAt(2);
data.RemoveAt(2);
data.Remove(6);
for (int i = 0; i < data.Count; i++)
Console.WriteLine(data[i]); // 7,3,4,10,9,1,8
Console.WriteLine();
data.AddRange(new int[] { 2, 5 });
data.Add(6);
for (int i = 0; i < data.Count; i++)
Console.WriteLine(data[i]); // 7,3,4,10,9,1,8,2,5,6
data.Sort();
Console.WriteLine();
for (int i = 0; i < data.Count; i++)
Console.WriteLine(data[i]); // 1,2,3,4,5,6,7,8,9,10
data.Clear();
data.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
data.RemoveAll(x => x % 2 == 0);
Console.WriteLine();
for (int i = 0; i < data.Count; i++)
Console.WriteLine(data[i]); // 1,3,5,7,9
data.Reverse();
Console.WriteLine();
foreach (int i in data)
Console.WriteLine(i); // 9,7,5,3,1
Dictionary<string, string> dict = new Dictionary<string, string>()
{
{ "Apple", "苹果" }, { "About", "关于" }, { "Apply", "应用" }, { "Above", "在...之下" }, { "Academic", "学术的" }
};
dict.Add("Apologize", "道歉");
dict.Add("Apartment", "公寓");
foreach (string key in dict.Keys)
Console.WriteLine("{0}: {1}", key.ToLower(), dict[key]);
bool b1 = dict.ContainsKey("Aspect");
bool b2 = dict.ContainsKey("Apply");
bool b3 = dict.ContainsValue("学术的");
Console.WriteLine("b1={0} b2={1} b3={2}", b1, b2, b3);
Queue<int> q = new Queue<int>();
q.Enqueue(1);
q.Enqueue(2);
q.Enqueue(3);
while (q.Count > 0)
Console.WriteLine(q.Dequeue());
Console.WriteLine();
Stack<int> s = new Stack<int>();
s.Push(1);
s.Push(2);
s.Push(3);
Console.WriteLine(s.Peek());
while (s.Count > 0)
Console.WriteLine(s.Pop());
public class Tree<T>
{
public Tree()
{
}
private List<T> thisNode;
public Tree<T> nextNode
{
get;
set;
}
public void Add(T t)
{
if (thisNode == null)
thisNode = new List<T>();
thisNode.Add(t);
}
public IEnumerator<T> GetEnumerator()
{
foreach (var temp in thisNode)
{
yield return temp;
}
}
}
挺好玩