- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2628 Articles for Csharp
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
240 Views
To add the element to HashSet, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo { public static void Main(String[] args){ HashSet set1 = new HashSet(); set1.Add("A"); set1.Add("B"); set1.Add("C"); set1.Add("D"); set1.Add("E"); set1.Add("F"); set1.Add("G"); set1.Add("H"); Console.WriteLine("Elements in HashSet1..."); foreach (string res in set1){ Console.WriteLine(res); } HashSet set2 = new HashSet(); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
183 Views
To get the fields of the current Type, the code is as follows −Example Live Demousing System; using System.Reflection; public class Demo { public static void Main() { Type type = typeof(System.String); FieldInfo [] fields = type.GetFields(BindingFlags.Static | BindingFlags.NonPublic); Console.WriteLine ("Following are the non-public fields="); foreach (FieldInfo myField in fields) { Console.WriteLine(myField.ToString()); } } }OutputThis will produce the following output −Following are the non-public fields= Int32 TrimHead Int32 TrimTail Int32 TrimBoth Int32 charPtrAlignConst Int32 alignConstExampleLet us see another example − Live Demousing System; using System.Reflection; public class Demo { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
161 Views
To get the handle for the Type of a specified object, the code is as follows −Example Live Demousing System; public class Demo { public static void Main() { Type type1 = typeof(System.Type); RuntimeTypeHandle typeHandle = Type.GetTypeHandle(type1); Type type = Type.GetTypeFromHandle(typeHandle); Console.WriteLine("Attributes = " + type.Attributes); Console.WriteLine("Type Referenced = "+ type); } }OutputThis will produce the following output −Attributes = AutoLayout, AnsiClass, Class, Serializable, BeforeFieldInit Type Referenced = System.RuntimeTypeExampleLet us see another example − Live Demousing System; public class Demo { public static void ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
86 Views
To check whether the Dictionary has the specified key or not, the code is as follows −Example Live Demousing System; using System.Collections.Generic; public class Demo { public static void Main() { Dictionary dict = new Dictionary(); dict.Add("One", "John"); dict.Add("Two", "Tom"); dict.Add("Three", "Jacob"); dict.Add("Four", "Kevin"); dict.Add("Five", "Nathan"); Console.WriteLine("Count of elements = "+dict.Count); Console.WriteLine("Key/value pairs..."); foreach(KeyValuePair res in dict) { Console.WriteLine("Key = {0}, Value = {1}", res.Key, res.Value); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
139 Views
To indicate whether the specified Unicode character is white space, the code is as follows −Example Live Demousing System; public class Demo { public static void Main() { bool res; char val = ' '; Console.WriteLine("Value = "+val); res = Char.IsWhiteSpace(val); Console.WriteLine("Is the value whitespace? = "+res); } }OutputThis will produce the following output −Value = Is the value whitespace? = TrueExampleLet us see another example − Live Demousing System; public class Demo { public static void Main() { bool res; ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
557 Views
The StringCollection class represents a collection of strings. Following are the properties of the StringCollection class −Sr.noProperty & Description1CountGets the number of key/values pairs contained in the OrderedDictionary collection.2IsReadOnlyGets a value indicating whether the StringCollection is read-only..3IsSynchronizedGets a value indicating whether access to the StringCollection is synchronized (thread safe).4Item[Int32]Gets or sets the element at the specified index.5SyncRootGets an object that can be used to synchronize access to the StringCollection.Following are the methods of the StringCollection class −Sr.noMethod & Description1Add(String)Adds a string to the end of the StringCollection.2AddRange(String[])Copies the elements of a string array to the end of the StringCollection.3Clear()Removes all ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
55 Views
To find the capacity of a StringBuilder in C#, the code is as follows −Example Live Demousing 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(); Console.WriteLine("Capacity of StringBuilder1 = "+strBuilder1.Capacity); Console.WriteLine("Capacity of StringBuilder2 = "+strBuilder2.Capacity); Console.WriteLine("Capacity of StringBuilder3 = "+strBuilder3.Capacity); strBuilder2 = strBuilder3; Console.WriteLine("Is StringBuilder3 equal to StringBuilder2? = "+strBuilder3.Equals(strBuilder2)); } }OutputThis will produce the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
101 Views
To get the total number of elements present in an array, the code is as follows −Example Live Demousing System; public class Demo { public static void Main() { string[] products = { "Electronics", "Accessories", "Clothing", "Toys", "Clothing", "Furniture" }; Console.WriteLine("Products list..."); foreach(string s in products) { Console.WriteLine(s); } Console.WriteLine("Array length = "+products.GetLength(0)); Console.WriteLine("One or more products begin with the letter 'C'? = {0}", Array.Exists(products, ele => ele.StartsWith("C"))); Console.WriteLine("One or more planets begin with 'D'? ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
90 Views
To create StringBuilder in C#, the code is as follows −Example Live Demousing System; using System.Text; public class Demo { public static void Main(String[] args) { StringBuilder strBuilder1 = new StringBuilder("Tim"); StringBuilder strBuilder2 = new StringBuilder("Tom"); Console.WriteLine("Is StringBuilder1 equal to StringBuilder2? = "+strBuilder1.Equals(strBuilder2)); } }OutputThis will produce the following output −Is StringBuilder1 equal to StringBuilder2? = FalseExampleLet us see another example − Live Demousing System; using System.Text; public class Demo { public static void Main(String[] args) { StringBuilder strBuilder1 = new StringBuilder("John"); StringBuilder strBuilder2 = new StringBuilder("John"); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
62 Views
To create an OrderedDictionary in C#, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() { OrderedDictionary dict = new OrderedDictionary(); dict.Add("A", "Books"); dict.Add("B", "Electronics"); dict.Add("C", "Smart Wearables"); dict.Add("D", "Pet Supplies"); dict.Add("E", "Clothing"); dict.Add("F", "Footwear"); Console.WriteLine("OrderedDictionary elements..."); foreach(DictionaryEntry d in dict) { Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("Count of ... Read More