Found 2628 Articles for Csharp

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

686 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

9K+ 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

5K+ 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

577 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

1K+ 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

C# Program to create Pascal’s Triangle

Chandu yadav
Updated on 26-Jun-2020 14:45:44

4K+ Views

A Pascal’s triangle contains numbers in a triangular form where the edges of the triangle are the number 1 and a number inside the triangle is the sum of the 2 numbers directly above it.A program that demonstrates the creation of the Pascal’s triangle is given as follows.Example Live Demousing System; namespace PascalTriangleDemo {    class Example {       public static void Main() {          int rows = 5, val = 1, blank, i, j;          Console.WriteLine("Pascal's triangle");          for(i = 0; i

C# program to implement FizzBuzz

George John
Updated on 20-Apr-2020 08:06:26

3K+ Views

Implementation of FizzBuzz involves printing numbers from 1 to 100. If the numbers are multiples of 3 then Fizz is printed. If they are multiples of 5, then Buzz is printed and if they are multiples of both 3 and 5 then FizzBuzz is printed.A program that demonstrates the implementation of FizzBuzz is given as follows.Example Live Demousing System; namespace FizzBuzzDemo {    public class example {       static void Main(string[] args) {          for (int i = 1; i

Advertisements