C# Program to find a value in a Hashtable

George John
Published on 12-Sep-2018 16:52:08
Set Hahtable collection with elements.Hashtable h = new Hashtable(); h.Add(1, "Jack"); h.Add(2, "Henry"); h.Add(3, "Ben"); h.Add(4, "Chris");Let’s say now you need to find a value, then use the ContainsValue() method.We are finding value “Chris” here −h.ContainsValue(“Chris”);Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() { ... Read More

C# Program to find a key in a Hashtable

karthikeya Boyini
Published on 12-Sep-2018 16:48:32
Set Hashtable collection with elements.Hashtable h = new Hashtable(); h.Add(1, "Jack"); h.Add(2, "Henry"); h.Add(3, "Ben"); h.Add(4, "Chris");Let’s say now you need to find any key, then use the Contains() method. We are finding key 3 here −h.Contains(3);The following is the complete example.Example Live Demousing System; using System.Collections; public class Demo { ... Read More

Remove an item from a Hashtable in C#

Ankith Reddy
Published on 12-Sep-2018 16:47:58
The following is our Hashtable −Hashtable h = new Hashtable(); h.Add(1, "Jack"); h.Add(2, "Henry"); h.Add(3, "Ben"); h.Add(4, "Chris");To remove an item, use the Remove() method. Here, we are removing the 3rd element.h.Remove(3);Let us see the complete example.Example Live Demousing System; using System.Collections; public class Demo {    public static void Main() ... Read More

C# Currency ("C") Format Specifier

Samual Sam
Published on 12-Sep-2018 16:44:46
The "C" (or currency) format specifier is used to convert a number to a string representing a currency amount.Let us see an example.double value = 139.87;Now to display the above number until three decimal places, use (“C3”) currency format specifier.value.ToString("C3", CultureInfo.CurrentCulture)Let us see another example.Example Live Demousing System; using System.Globalization; class ... Read More

LinkedList Contains Method in C#

Arjun Thakur
Published on 12-Sep-2018 16:44:23
Here is our LinkedList.int [] num = {1, 3, 7, 15}; LinkedList<int> list = new LinkedList<int>(num);To check whether the list contains an element or not, use the Contains() method. The following example checks for node 3 in the list.list.Contains(3)Above, returns True since the element is found as shown below −Example Live ... Read More

Long Date ("D") Format Specifier in C#

karthikeya Boyini
Published on 12-Sep-2018 16:41:20
The "D" format specifier represents a custom date and time format string.The format string is defined by culture's DateTimeFormatInfo.LongDatePattern property.The custom format string is −dddd, dd MMMM yyyyExample Live Demousing System; using System.Globalization; class Demo {    static void Main() {       DateTime myDate = new DateTime(2018, 9, 20); ... Read More

How to negate the positive elements of an integer array in C#?

Chandu yadav
Published on 12-Sep-2018 16:40:44
The following is the array and its elements −int[] arr = { 10, 20, 15 };Set negative value to positive elements.if (arr[i] > 0) arr[i] = -arr[i];Loop the above until the length of the array.for (int i = 0; i < arr.Length; i++) {    Console.WriteLine(arr[i]);    if (arr[i] > ... Read More

The "%" custom specifier in C#

Samual Sam
Published on 12-Sep-2018 16:37:18
A % in a format string would multiply a number by 100 before it is formatted.The percent symbol is added in the number at the location where the % appears.For an example, declare and initialize a double variable.double d = .045;Now, use % custom specifier to multiply number by 100.d.ToString("#0.##%", ... Read More

Clear a Linked List in C#

George John
Published on 12-Sep-2018 16:37:21
Clear a LinkedList using Clear() method.Let us first set a LinkedList.string [] employees = {"Patrick", "Robert", "John", "Jacob", "Jamie"}; LinkedList<string> list = new LinkedList<string>(employees);Now, let us clear the LinkedList.list.Clear();Let us see the complete code.Example Live Demousing System; using System.Collections.Generic; class Demo {    static void Main() {       string ... Read More

C# Enum ToString() Method

karthikeya Boyini
Published on 12-Sep-2018 16:33:52
The ToString() method converts the value of this instance to its equivalent string representation.Firstly, set an enum.enum Vehicle { Car, Bus, Truck, Motobike };To convert it to an equivalent string representation, use ToString().Vehicle.Car.ToString("d")Example Live Demousing System; public class Demo {    enum Vehicle { Car, Bus, Truck, Motobike };    public ... Read More
Advertisements