004days
Statck__Queue(栈和队列)ArrayListDictionaryListHashtable
Statck__Queue(栈和队列)
using System;
using System.Collections;
namespace Statck__Queue
{
class Program
{
static void Main(string[] args)
{
STATCK();
QUEUE();
}
public static void STATCK()
{
Stack s = new Stack();
s.Push("hello");
s.Push("h");
s.Push("e");
s.Push("l");
s.Push("o");
object ele = s.Peek();
Console.WriteLine(ele);
object e = s.Pop();
foreach (object obj in s)
{
Console.WriteLine(obj);
}
}
public static void QUEUE()
{
Queue q = new Queue();
q.Enqueue("hello");
q.Enqueue("h");
q.Enqueue("e");
q.Enqueue("l");
q.Enqueue("o");
object ele = q.Peek();
Console.WriteLine(ele);
object e = q.Dequeue();
}
}
}
ArrayList
using System;
using System.Collections;
namespace housebook5
{
#region
#endregion
#region
#endregion
}```
## Dictionary
```csharp
using System;
using System.Collections.Generic;
namespace Dictionary
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, string> dic = new Dictionary<string, string>();
AddOperation(dic);
RemoveOperation(dic);
UpdateOperation(dic);
SearchOperation(dic);
}
static void AddOperation(Dictionary<string, string> dic)
{
dic.Add("name", "xiaohong");
dic.Add("age", "10");
dic.Add("gender", "male");
dic.Add("score", "59.9");
}
static void RemoveOperation(Dictionary<string, string> dic)
{
dic.Remove("age");
}
static void UpdateOperation(Dictionary<string, string> dic)
{
dic["name"] = "laowang";
}
static void SearchOperation(Dictionary<string, string> dic)
{
foreach(KeyValuePair<string,string> obj in dic)
{
Console.WriteLine(obj);
}
foreach (KeyValuePair<string, string> obj in dic)
{
string key = obj.Key;
string value = obj.Value;
Console.WriteLine($"{key}={value}");
}
ICollection<string> keys = dic.Keys;
foreach(string key in keys)
{
string value = dic[key];
Console.WriteLine($"{key}={value}");
}
}
}
}
List
using System;
using System.Collections.Generic;
namespace Other
{
class Program
{public static void Main(string[] args)
{
List<int> list = new List<int>();
list.AddRange(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
bool result = list.Exists(number => number % 2 != 0);
Console.WriteLine(result);
int n = list.Find(number => number % 2 != 0);
Console.WriteLine(n);
List<int> results= list.FindAll(number => number % 2 != 0);
list.FindIndex(number => number % 2 != 0);
list.FindLast(number => number % 2 != 0);
list.RemoveAll(number => number % 2 != 0);
}
}
}
Hashtable
using System;
using System.Collections;
namespace xiaoming
{
class Program
{
static void Main(string[] args)
{
Hashtable table = new Hashtable();
AddaOperation(table);
RemoveOperation(table);
UpdateOperation(table);
searchOperation(table);
OtherOperation(table);
}
public static void AddaOperation(Hashtable table)
{
table.Add("name", "xiaoming");
table.Add(1, "xiaoming");
table.Add("xiaomingd", 10);
table.Add(false, true);
}
public static void RemoveOperation(Hashtable table)
{
table.Remove("name");
}
public static void UpdateOperation(Hashtable table)
{
table["name"] = "laowang";
table["height"] = 173;
}
public static void searchOperation(Hashtable table)
{
ICollection keys = table.Keys;
foreach(object key in keys)
{
object value = table[key];
Console.WriteLine($"{ key}={value}");
}
}
public static void OtherOperation(Hashtable table) {
bool result = table.Contains("age");
}
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-65420.html