找到 2628 篇文章 关于 C#
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.CurrentThread.IsThreadPoolThread); } }输出这将产生以下输出:ManagedThreadId = 3 线程属于托管线程池? = True示例让我们现在... 阅读更多
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("Tuple1 等于 Tuple2? = "+tuple1.Equals(tuple2)); Console.WriteLine("Tuple1 的哈希码 = "+tuple1.GetHashCode()); Console.WriteLine("Tuple1 的类型 = "+tuple1.GetType()); Console.WriteLine("Tuple2 的哈希码 = "+tuple2.GetHashCode()); Console.WriteLine("Tuple1 的类型 = "+tuple2.GetType()); } }输出这将产生以下输出:Tuple1 等于 Tuple2? = ... 阅读更多
150 次浏览
要获取当前实例的类型,代码如下所示:示例 在线演示using System; public class Demo { public static void Main(){ string s = "Demo"; Console.WriteLine("字符串 = " +s); Console.WriteLine("字符串类型 = " +s.GetType()); } }输出这将产生以下输出:字符串 = Demo 字符串类型 = System.String示例让我们现在看看另一个示例: 在线演示using System; public class Demo { public static void Main(){ double val1 = 5.5; int val2 = 10; short val3 = 2; ... 阅读更多
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("显示一定范围内的元素..."); IEnumerator demoEnum = arrList.GetEnumerator(1, 3); while (demoEnum.MoveNext()) { Object ob = demoEnum.Current; Console.WriteLine(ob); } } ... 阅读更多
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 的长度 = "+arr1.Length); Console.WriteLine("BitArray1 的第一个元素 = "+arr1.Get(0)); arr2[0] = false; arr2[1] = true; Console.WriteLine("BitArray2 的长度 = "+arr2.Length); ... 阅读更多
728 次浏览
要获取元组的第一个元素,代码如下所示:示例 在线演示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("Tuple1 等于 Tuple2? = "+tuple1.Equals(tuple2)); Console.WriteLine("Tuple1 的哈希码 = "+tuple1.GetHashCode()); Console.WriteLine("Tuple2 的哈希码 = "+tuple2.GetHashCode()); Console.WriteLine("Tuple1 的第 5 个元素 = "+tuple1.Item5); Console.WriteLine("Tuple2 的第 5 个元素 = "+tuple2.Item5); Console.WriteLine("Tuple1 的第 1 个元素... 阅读更多
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 的元素..."); foreach(DictionaryEntry d in dict1){ Console.WriteLine(d.Key + " " + d.Value); } ListDictionary dict2 ... 阅读更多
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("List1 中的元素..."); foreach (string res in list1){ Console.WriteLine(res); } List list2 = new List(); list2.Add("India"); list2.Add("US"); list2.Add("UK"); ... 阅读更多
91 次浏览
要从 Hashtable 中删除指定键的元素,代码如下所示:示例 在线演示using 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 ... 阅读更多
77 次浏览
要获取元组的第五个元素,代码如下所示:示例 在线演示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("Tuple1 等于 Tuple2? = "+tuple1.Equals(tuple2)); Console.WriteLine("Tuple1 的哈希码 = "+tuple1.GetHashCode()); Console.WriteLine("Tuple2 的哈希码 = "+tuple2.GetHashCode()); Console.WriteLine("Tuple1 的第 5 个元素 = "+tuple1.Item5); Console.WriteLine("Tuple2 的第 5 个元素 = "+tuple2.Item5); } }输出这将产生... 阅读更多