
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 26504 Articles for Server Side Programming

192 Views
To check if OrderedDictionary collection contains a specific key, 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("1", "One"); dict.Add("2", "Two"); dict.Add("3", "Three"); dict.Add("4", "Four"); dict.Add("5", "Five"); dict.Add("6", "Six"); dict.Add("7", "Seven"); dict.Add("8", "Eight"); ICollection col = dict.Values; String[] strVal = new String[dict.Count]; col.CopyTo(strVal, 0); ... Read More

237 Views
To get the hash code for this instance, the code is as follows −Example Live Demousing System; public class Demo { public static void Main() { string[] arr = {"tom", "amit", "kevin", "katie"}; Type t1 = arr.GetType(); Type t2 = t1.GetElementType(); Console.WriteLine("Type = "+t2.ToString()); Console.WriteLine("Hash Code = "+t1.GetHashCode()); } }OutputThis will produce the following output −Type = System.String Hash Code = 9144789ExampleLet us see another example − Live Demousing System; public class Demo { enum Vehicle {Car, Bus, Bike, Airplane} public static void ... Read More

305 Views
To add an element into the Hashtable, the code is as follows −Example Live Demousing 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 Key and Value pairs..."); foreach(DictionaryEntry entry in hash){ ... Read More

443 Views
To get a specific field of the current type in C#, the code is as follows −Example Live Demousing System; using System.Reflection; public class Demo { public static void Main() { Type type = typeof(Subject); try { FieldInfo fieldInfo = type.GetField("SubName"); Console.WriteLine("FieldInfo = {0}", fieldInfo); } catch (ArgumentNullException e) { Console.Write("{0}", e.GetType(), e.Message); } } } public class Subject { public string SubName = "Science"; }OutputThis will produce the following output −FieldInfo = ... Read More

149 Views
To add the specified key and value into the ListDictionary, the code is as follows −Example Live Demousing System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ ListDictionary dict = new ListDictionary(); dict.Add("1", "One"); dict.Add("2", "Two"); dict.Add("3", "Three"); dict.Add("4", "Four"); dict.Add("5", "Five"); Console.WriteLine("ListDictionary key-value pairs..."); IDictionaryEnumerator demoEnum = dict.GetEnumerator(); while (demoEnum.MoveNext()) Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + demoEnum.Value); } ... Read More

126 Views
To get the array of the values of the constants in the current enumeration type, the code is as follows −Example Live Demousing System; public class Demo { enum Vehicle {Car, Bus, Bike, Airplane} public static void Main() { try { Type type = typeof(int); string[] str = type.GetEnumNames(); Console.WriteLine("GetEnumNames() to return the constant name = " + str); Type type2 = type.GetEnumUnderlyingType(); Console.Write("Enum Underlying type = "+type2); Array arrObj = type.GetEnumValues(); ... Read More

322 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

282 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

228 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

156 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