Csharp Articles - Page 122 of 258

Char.IsControl(String, Int32) Method in C#

AmitDiwan
Updated on 04-Nov-2019 08:06:22

556 Views

The Char.IsControl(String, Int32) method in C# is used to indicate whether the character at the specified position in a specified string is categorized as a control character.Syntaxpublic static bool IsControl (string str, int index);Above, str is a string. The index parameter is the position of the character to evaluate in str.Let us now see an example to implement the Char.IsControl(String, Int32) method −Exampleusing System; using System.Globalization; public class Demo {    public static void Main(){       string val = "hjk9878hj";       Console.WriteLine("String = "+val);       UnicodeCategory unicode = Char.GetUnicodeCategory(val, 4);       Console.WriteLine("The ... Read More

Dictionary.ContainsValue() Method in C#

AmitDiwan
Updated on 04-Nov-2019 07:59:08

4K+ Views

The Dictionary.ContainsValue() method in C# is used to check whether the Dictionary contains a specific value or not.Syntaxpublic bool ContainsValue (TValue val);Above, Val is the value to be searched.Let us now see an example to implement the Dictionary.ContainsValue() method −Exampleusing 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 ... Read More

Dictionary.ContainsKey() Method in C#

AmitDiwan
Updated on 04-Nov-2019 07:49:19

2K+ Views

The Dictionary.ContainsKey() method in C# checks whether the Dictionary

Shell Sort program in C#

George John
Updated on 27-Jun-2020 06:24:13

890 Views

Shell Sort allows the exchange of items that are far apart in the array and then reduces the gap between them. This is a sort of generalization of Insertion Sort. Shell Sort is known as such as it was published by Donald Shell at first.A program that demonstrates shell sort in C# is given as follows −Example Live Demousing System; namespace ShellSortDemo {    public class Example {       static void shellSort(int[] arr, int n) {          int i, j, pos, temp;          pos = 3;          while (pos > ... Read More

How to multiply a given number by 2 using Bitwise Operators in C#?

Ankith Reddy
Updated on 27-Jun-2020 06:43:29

4K+ Views

A number can be multiplied by 2 using bitwise operators. This is done by using the left shift operator and shifting the bits left by 1. This results in double the previous number.A program that demonstrates multiplication of a number by 2 using bitwise operators is given as follows.Example Live Demousing System; namespace BitwiseDemo {    class Example {       static void Main(string[] args) {          int num = 25, result;          result = num

How to perform Merge Sort using C#?

Arjun Thakur
Updated on 27-Jun-2020 06:50:48

2K+ Views

Merge Sort is a sorting algorithm that uses the divide and conquer method. It divides the array into two parts and then calls itself for each of these two parts. This process is continued until the array is sorted.A program that demonstrates merge sort in C# is given as follows −Example Live Demousing System; namespace QuickSortDemo {    class Example {       static public void merge(int[] arr, int p, int q, int r) {          int i, j, k;          int n1 = q - p + 1;          int ... Read More

C# program to multiply two matrices

Chandu yadav
Updated on 26-Jun-2020 14:37:01

12K+ Views

The program for matrix multiplication is used to multiply two matrices. This procedure is only possible if the number of columns in the first matrix are equal to the number of rows in the second matrix.A program that demonstrates matrix multiplication in C# is given as follows −Example Live Demousing System; namespace MatrixMultiplicationDemo {    class Example {       static void Main(string[] args) {          int m = 2, n = 3, p = 3, q = 3, i, j;          int[, ] a = {{1, 4, 2}, {2, 5, 1}};     ... Read More

C# program to perform Quick sort using Recursion

George John
Updated on 26-Jun-2020 14:41:50

6K+ Views

Quick Sort is a sorting algorithm that uses the divide and conquer method. It takes a pivot element and places it in its correct position. Then the array to the left and right of the pivot element are again sorted using Quick Sort. This is done until the whole array is sorted.A program that demonstrates Quick Sort using Recursion in C# is given as follows −Example Live Demousing System; namespace QuickSortDemo {    class Example {       static public int Partition(int[] arr, int left, int right) {          int pivot;          pivot = ... Read More

How to access elements of an array using pointer notation in C#?

Ankith Reddy
Updated on 26-Jun-2020 14:43:07

882 Views

Usage of pointers in C# require the unsafe modifier. Also array elements can be accessed using pointers using the fixed keyword. This is because the array and the pointer data type are not the same. For example: The data type int[] is not the same as int*.A program that demonstrates accessing array elements using pointers is given as follows.Exampleusing System; namespace PointerDemo {    class Example {       public unsafe static void Main() {          int[] array = {55, 23, 90, 76, 9, 57, 18, 89, 23, 5};          int n = ... Read More

Validate IP Address in C#

Arjun Thakur
Updated on 26-Jun-2020 14:43:52

2K+ Views

An IP Address is an Internet Protocol address that is a series of numbers assigned to each device on a computer network. In C#, the class IPAddress class in the namespace System.Net deals with IP addresses.A program that is used to validate an IP address is given as follows −Example Live Demousing System; using System.Net; using System.Net.Sockets; using System.Text.RegularExpressions; namespace IPaddressDemo {    class Example {       public static void Main() {          IPAddress IP;          Console.WriteLine("Enter the IP Address: ");          string ipAddr = Console.ReadLine();         ... Read More

Advertisements