找到 34423 篇文章 关于编程

如何在 C# 中向 SortedList 添加键值对?

AmitDiwan
更新于 2019年12月6日 07:54:46

224 次浏览

要在 SortedList 中添加键值对,代码如下所示:示例 在线演示using System; using System.Collections; public class Demo {    public static void Main(String[] args){       SortedList list = new SortedList();       list.Add("A", "Jacob");       list.Add("B", "Sam");       list.Add("C", "Tom");       list.Add("D", "John");       list.Add("E", "Tim");       list.Add("F", "Mark");       list.Add("G", "Gary");       list.Add("H", "Nathan");       list.Add("I", "Shaun");       list.Add("J", "David");       ICollection col1 = list.Values;       Console.WriteLine("Values...");       foreach(string s ... 阅读更多

获取 C# 中当前托管线程的唯一标识符

AmitDiwan
更新于 2019年12月6日 07:51:15

148 次浏览

要获取当前托管线程的唯一标识符,代码如下所示:示例 在线演示using System; using System.Threading; public class Demo {    public static void Main(){       Thread thread = new Thread(new ThreadStart(demo1));       ThreadPool.QueueUserWorkItem(new WaitCallback(demo2));       Console.WriteLine("ManagedThreadId = "+thread.ManagedThreadId);    }    public static void demo1(){       Thread.Sleep(2000);    }    public static void demo2(object stateInfo){       Console.WriteLine("Thread belongs to managed thread pool? = "+Thread.CurrentThread.IsThreadPoolThread);    } }输出这将产生以下输出:ManagedThreadId = 3 Thread belongs to managed thread pool? = True示例现在让我们... 阅读更多

获取 C# 中元组元素的类型

AmitDiwan
更新于 2019年12月6日 07:48:05

44 次浏览

要获取元组元素的类型,代码如下所示:示例 在线演示using System; public class Demo {    public static void Main(String[] args){       var tuple1 = Tuple.Create(150, 1500, Tuple.Create(50, 100));       var tuple2 = Tuple.Create(150, 1500, Tuple.Create(100, 200));       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));       Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());       Console.WriteLine("Type of Tuple1 = "+tuple1.GetType());       Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());       Console.WriteLine("Type of Tuple1 = "+tuple2.GetType());    } }输出这将产生以下输出:Is Tuple1 equal to ... 阅读更多

获取 C# 中当前实例的类型

AmitDiwan
更新于 2019年12月6日 07:42:28

150 次浏览

要获取当前实例的类型,代码如下所示:示例 在线演示using System; public class Demo {    public static void Main(){       string s = "Demo";       Console.WriteLine("String = " +s);       Console.WriteLine("String Type = " +s.GetType());    } }输出这将产生以下输出:String = Demo String Type = System.String示例现在让我们来看另一个示例: 在线演示using System; public class Demo {    public static void Main(){       double val1 = 5.5;       int val2 = 10;       short val3 = 2; ... 阅读更多

获取 C# 中 ArrayList 中一部分元素的枚举器

AmitDiwan
更新于 2019年12月6日 07:39:34

89 次浏览

要获取 ArrayList 中一部分元素的枚举器,代码如下所示:示例 在线演示using System; using System.Collections; public class Demo {    public static void Main(){       ArrayList arrList = new ArrayList();       arrList.Add(100);       arrList.Add(200);       arrList.Add(300);       arrList.Add(400);       arrList.Add(500);       Console.WriteLine("Display elements in a range...");       IEnumerator demoEnum = arrList.GetEnumerator(1, 3);       while (demoEnum.MoveNext()) {          Object ob = demoEnum.Current;          Console.WriteLine(ob);       }    } ... 阅读更多

获取或设置 C# 中 BitArray 中特定位置的位值

AmitDiwan
更新于 2019年12月6日 07:36:21

91 次浏览

要获取或设置 BitArray 中特定位置的位值,代码如下所示:示例 在线演示using System; using System.Collections; public class Demo {    public static void Main(){       BitArray arr1 = new BitArray(2);       BitArray arr2 = new BitArray(2);       arr1[0] = false;       arr1[1] = true;       Console.WriteLine("BitArray1 length = "+arr1.Length);       Console.WriteLine("BitArray1 first element = "+arr1.Get(0));       arr2[0] = false;       arr2[1] = true;       Console.WriteLine("BitArray2 length = "+arr2.Length);       ... 阅读更多

如何在 C# 中获取元组的第一个元素?

AmitDiwan
更新于 2019年12月6日 07:22:50

729 次浏览

要获取元组的第一个元素,代码如下所示:示例 在线演示using System; public class Demo {    public static void Main(String[] args){       var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       Console.WriteLine("Is Tuple1 equal to Tuple2? = "+tuple1.Equals(tuple2));       Console.WriteLine("HashCode of Tuple1 = "+tuple1.GetHashCode());       Console.WriteLine("HashCode of Tuple2 = "+tuple2.GetHashCode());       Console.WriteLine("Tuple1 Item 5th = "+tuple1.Item5);       Console.WriteLine("Tuple2 Item 5th = "+tuple2.Item5);       Console.WriteLine("Tuple1 Item 1st ... 阅读更多

检查 C# 中两个 ListDictionary 对象是否相等

AmitDiwan
更新于 2019年12月6日 07:15:24

104 次浏览

要检查两个 ListDictionary 对象是否相等,代码如下所示:示例 在线演示using System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main(){       ListDictionary dict1 = new ListDictionary();       dict1.Add("A", "Books");       dict1.Add("B", "Electronics");       dict1.Add("C", "Smart Wearables");       dict1.Add("D", "Pet Supplies");       dict1.Add("E", "Clothing");       dict1.Add("F", "Footwear");       Console.WriteLine("ListDictionary1 elements...");       foreach(DictionaryEntry d in dict1){          Console.WriteLine(d.Key + " " + d.Value);       }       ListDictionary dict2 ... 阅读更多

检查 C# 中两个 List 对象是否相等

AmitDiwan
更新于 2019年12月6日 07:09:29

319 次浏览

要检查两个 List 对象是否相等,代码如下所示:示例 在线演示using System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args){       List list1 = new List();       list1.Add("One");       list1.Add("Two");       list1.Add("Three");       list1.Add("Four");       list1.Add("Five");       Console.WriteLine("Elements in List1...");       foreach (string res in list1){          Console.WriteLine(res);       }       List list2 = new List();       list2.Add("India");       list2.Add("US");       list2.Add("UK");   ... 阅读更多

从 C# 中的 Hashtable 中删除具有指定键的元素

AmitDiwan
更新于 2019年12月6日 07:06:52

91 次浏览

要从哈希表中移除具有指定键的元素,代码如下:示例 在线演示使用 System; using System.Collections; public class Demo {    public static void Main(){       Hashtable hash = new Hashtable(10);       hash.Add("1", "A");       hash.Add("2", "B");       hash.Add("3", "C");       hash.Add("4", "D");       hash.Add("5", "E");       hash.Add("6", "F");       hash.Add("7", "G");       hash.Add("8", "H");       hash.Add("9", "I");       hash.Add("10", "J");       Console.WriteLine("Hashtable 键值对...");       foreach(DictionaryEntry ... 阅读更多

广告
© . All rights reserved.