找到 34423 篇文章 关于编程

在 C# 中获取由指定类型句柄引用的类型

AmitDiwan
更新于 2019年12月10日 07:36:55

139 次浏览

要获取由指定类型句柄引用的类型,代码如下所示:示例 在线演示using System; public class Demo {    public static void Main() {       Type type1 = typeof(short);       RuntimeTypeHandle typeHandle = Type.GetTypeHandle(type1);       Type type = Type.GetTypeFromHandle(typeHandle);       Console.WriteLine("Attributes = " + type.Attributes);    } }输出这将产生以下输出:Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit示例让我们看另一个示例: 在线演示using System; public class Demo {    public static void Main() {       Type type1 = typeof(System.Type);       RuntimeTypeHandle ... 阅读更多

在 C# 中将指定值转换为等效的布尔值

AmitDiwan
更新于 2019年12月10日 07:33:49

278 次浏览

要将指定值转换为等效的布尔值,代码如下所示:示例 在线演示using System; using System.Globalization; public class Demo {    public static void Main() {       CultureInfo cultures = new CultureInfo("en-US");       String str = "true";       Console.WriteLine("Converted bool value...");       bool res = Convert.ToBoolean(str, cultures);       Console.Write("{0}", res);    } }输出这将产生以下输出:Converted bool value... True示例让我们看另一个示例: 在线演示using System; using System.Globalization; public class Demo {    public static void Main() {       CultureInfo cultures ... 阅读更多

在 C# 中获取或设置具有指定键的 HybridDictionary 中的值

AmitDiwan
更新于 2019年12月10日 07:28:29

99 次浏览

要获取或设置具有指定键的 HybridDictionary 中的值,代码如下所示:示例 在线演示using System; using System.Collections.Specialized; public class Demo {    public static void Main() {       HybridDictionary myDict = new HybridDictionary();       myDict.Add("1", "Tablet");       myDict.Add("2", "Desktop");       myDict.Add("3", "Speakers");       myDict.Add("4", "Laptop");       myDict.Add("5", "Notebook");       myDict.Add("6", "Ultrabook");       myDict.Add("7", "HDD");       myDict.Add("8", "SDD");       Console.WriteLine("Value at key 5 = "+myDict["5"]);    } }输出这将产生以下输出:Value at key 5 ... 阅读更多

在 C# 中获取或设置 StringDictionary 中指定键处的值

AmitDiwan
更新于 2019年12月10日 07:12:16

89 次浏览

要获取或设置 StringDictionary 中指定键处的值,代码如下所示:示例 在线演示using System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringDictionary myDict = new StringDictionary();       myDict.Add("1", "Tablet");       myDict.Add("2", "Desktop");       myDict.Add("3", "Speakers");       myDict.Add("4", "Laptop");       myDict.Add("5", "Notebook");       myDict.Add("6", "Ultrabook");       myDict.Add("7", "HDD");       myDict.Add("8", "SDD");       myDict.Add("9", "Headphone");       myDict.Add("10", "Earphone");       Console.WriteLine("Value for key 5 = "+myDict["5"]);   ... 阅读更多

从 C# 中的 StringCollection 中删除所有字符串

AmitDiwan
更新于 2019年12月10日 07:09:38

92 次浏览

要从 StringCollection 中删除所有字符串,代码如下所示:示例 在线演示using System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringCollection stringCol = new StringCollection();       String[] arr = new String[] { "100", "200", "300", "400", "500" };       Console.WriteLine("Array elements...");       foreach (string res in arr) {          Console.WriteLine(res);       }       stringCol.AddRange(arr);       Console.WriteLine("Does the specified string is in the StringCollection? = "+stringCol.Contains("800"));       Console.WriteLine("Total number of elements = "+stringCol.Count); ... 阅读更多

从 C# 中的列表中删除所有元素

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

103 次浏览

要从列表中删除所有元素,代码如下所示:示例 在线演示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");       ... 阅读更多

获取 C# 中集合中包含的元素数

AmitDiwan
更新于 2019年12月10日 06:59:45

78 次浏览

要获取集合中包含的元素数,代码如下所示:示例 在线演示using System; using System.Collections.ObjectModel; public class Demo {    public static void Main() {       Collection col = new Collection();       col.Add("Andy");       col.Add("Kevin");       col.Add("John");       col.Add("Kevin");       col.Add("Mary");       col.Add("Katie");       col.Add("Barry");       col.Add("Nathan");       col.Add("Mark");       Console.WriteLine("Count of elements = "+ col.Count);       Console.WriteLine("Iterating through the collection...");       var enumerator = col.GetEnumerator();       while ... 阅读更多

在 C# 中获取或设置列表中指定索引处的元素

AmitDiwan
更新于 2019年12月10日 06:55:43

108 次浏览

要获取或设置列表中指定索引处的元素,代码如下所示:示例 在线演示using System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args) {       List list = new List();       list.Add("100");       list.Add("200");       list.Add("300");       list.Add("400");       list.Add("500");       list.Add("600");       list.Add("700");       list.Add("800");       list.Add("900");       list.Add("1000");       Console.WriteLine("Element at index 0 = " + list[0]);       Console.WriteLine("Element at index 1 ... 阅读更多

在 C# 中获取或设置 StringCollection 中指定索引处的元素

AmitDiwan
更新于 2019年12月10日 06:47:59

65 次浏览

要获取或设置 StringCollection 中指定索引处的元素,代码如下所示:示例 在线演示using System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringCollection strCol = new StringCollection();       String[] strArr = new String[] { "A", "B", "C", "D", "E", "F", "G", "H" };       Console.WriteLine("StringCollection elements...");       foreach (string str in strArr) {          Console.WriteLine(str);       }       strCol.AddRange(strArr);       Console.WriteLine("Element at 5th index = "+strCol[5]);       Console.WriteLine("Count of strings ... 阅读更多

在 C# 中获取包含 Hashtable 中值的 ICollection

AmitDiwan
更新于 2019年12月10日 06:42:56

79 次浏览

要获取包含哈希表中值的 ICollection,代码如下所示 - 示例 实时演示使用 System; using System.Collections; public class Demo {    public static void Main() {       Hashtable hash = new Hashtable();       hash.Add("A", "Electronics");       hash.Add("B", "Appliances");       hash.Add("C", "Pet Supplies");       hash.Add("D", "Books");       hash.Add("E", "Toys");       hash.Add("F", "Footwear");       hash.Add("G", "Clothing");       ICollection col = hash.Keys;       foreach(string str in col)       Console.WriteLine(str + ": " + hash[str]);    } }输出这... 阅读更多

广告
© . All rights reserved.