找到关于 C# 的2628 篇文章
69 次浏览
要获取元组的剩余元素,可以使用 Rest 属性。代码如下所示:示例 在线演示using System; public class Demo { public static void Main(String[] args){ var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, 2000); var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500, 2000); Console.WriteLine("Tuple1 是否等于 Tuple2? = "+tuple1.Equals(tuple2)); Console.WriteLine("Tuple1 的哈希码 = "+tuple1.GetHashCode()); Console.WriteLine("Tuple2 的哈希码 = "+tuple2.GetHashCode()); Console.WriteLine("Tuple1 的第一个元素 = "+tuple1.Item1); Console.WriteLine("Tuple2 的第一个元素 ... 阅读更多
414 次浏览
要获取列表中第一个匹配指定条件的元素,代码如下所示:示例 在线演示using System; using System.Collections.Generic; public class Demo { private static bool demo(int i){ return ((i % 10) == 0); } public static void Main(String[] args){ List
203 次浏览
要查找数组中最后一个元素的索引,代码如下所示:示例 在线演示using System; public class Demo { public static void Main(){ string[] products = new string[] { "Andy", "Mark", "Gary", "Andre"}; Console.WriteLine("一个或多个名称以 'A' 开头? = {0}", Array.Exists(products, ele => ele.StartsWith("A"))); Console.WriteLine("数组是否具有固定大小? = " + products.IsFixedSize); Console.WriteLine("数组是否只读? = " + products.IsReadOnly); Console.WriteLine("数组是否已同步? = " + products.IsSynchronized); Console.WriteLine("索引 ... 阅读更多
67 次浏览
要查找链表中包含指定值的第一个节点,代码如下所示:示例 在线演示using System; using System.Collections.Generic; public class Demo { public static void Main(){ LinkedList
91 次浏览
以下是使用枚举器迭代 BitArray 的代码:示例 在线演示using System; using System.Collections; public class Demo { public static void Main(){ BitArray arr1 = new BitArray(5); BitArray arr2 = new BitArray(5); arr1[0] = false; arr1[1] = true; arr1[2] = false; arr1[3] = true; arr1[4] = true; Console.WriteLine("迭代 BitArray1 的枚举器"); IEnumerable demoEnum = arr1; foreach(Object ob in demoEnum){ Console.WriteLine(ob); ... 阅读更多
83 次浏览
要创建具有指定容量的 StringBuilder,代码如下所示:示例 在线演示using System; using System.Text; public class Demo { public static void Main(String[] args){ StringBuilder strBuilder1 = new StringBuilder("Tim"); StringBuilder strBuilder2 = new StringBuilder("Tom"); StringBuilder strBuilder3 = new StringBuilder(); StringBuilder strBuilder4 = new StringBuilder(5); strBuilder2 = strBuilder3; Console.WriteLine("StringBuilder3 是否等于 StringBuilder2? = "+strBuilder3.Equals(strBuilder2)); Console.WriteLine("StringBuider1 容量 = "+strBuilder1.Capacity); Console.WriteLine("StringBuider2 容量 = "+strBuilder2.Capacity); Console.WriteLine("StringBuider3 容量 = "+strBuilder3.Capacity); Console.WriteLine("StringBuider4 容量 ... 阅读更多
102 次浏览
要为 SortedList 对象创建同步包装器,代码如下所示:示例 在线演示using System; using System.Collections; public class Demo { public static void Main(){ SortedList sortedList = new SortedList(); sortedList.Add("1", "Tom"); sortedList.Add("2", "Ryan"); sortedList.Add("3", "Nathan"); Console.WriteLine("SortedList 元素..."); foreach(DictionaryEntry d in sortedList){ Console.WriteLine("键 = "+d.Key + ", 值 = " + d.Value); } SortedList sortedList2 = SortedList.Synchronized(sortedList); Console.WriteLine("SortedList 是否已同步? = "+sortedList2.IsSynchronized); } }输出这将 ... 阅读更多
70 次浏览
要计算 HybridDictionary 中键值对的数量,代码如下所示:示例 在线演示using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ HybridDictionary dict1 = new HybridDictionary(); dict1.Add("A", "SUV"); dict1.Add("B", "MUV"); dict1.Add("C", "AUV"); Console.WriteLine("HybridDictionary1 元素..."); foreach(DictionaryEntry d in dict1){ Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("Dictionary1 中键值对的数量 = "+dict1.Count); HybridDictionary dict2 = new HybridDictionary(); ... 阅读更多
161 次浏览
要将 SortedList 元素复制到数组对象,代码如下所示:示例 在线演示using System; using System.Collections; public class Demo { public static void Main(String[] args){ SortedList list = new SortedList(); list.Add("1", "AB"); list.Add("2", "CD"); list.Add("3", "EF"); list.Add("4", "GH"); list.Add("5", "IJ"); list.Add("6", "JK"); list.Add("7", "KL"); list.Add("8", "LM"); Console.WriteLine("SortedList 元素..."); foreach(DictionaryEntry d in list){ Console.WriteLine("键 = "+d.Key + ", 值 = ... 阅读更多
75 次浏览
将 HybridDictionary 条目复制到数组实例的代码如下 - 示例 演示使用 System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ HybridDictionary dict = new HybridDictionary(); dict.Add("1", "SUV"); dict.Add("2", "AUV"); dict.Add("3", "多用途车辆"); dict.Add("4", "MUV"); dict.Add("5", "小型车"); dict.Add("6", "敞篷车"); Console.WriteLine("HybridDictionary 键值对..."); foreach(DictionaryEntry entry in dict){ Console.WriteLine("{0} 和 {1} ", entry.Key, entry.Value); } ... 阅读更多