Csharp Articles - Page 123 of 258

C# Program to create Pascal’s Triangle

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

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

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

Heap Sort in C#

Ankith Reddy
Updated on 26-Jun-2020 14:27:51

3K+ Views

Heap Sort is a sorting algorithm that makes use of the heap data structure. Each time the root element of the heap i.e. the largest element is removed and stored in an array. It is replaced by the rightmost leaf element and then the heap is reestablished. This is done until there are no more elements left in the heap and the array is sorted.A program that demonstrates heap sort in C# is given as follows.Example Live Demousing System; namespace HeapSortDemo {    public class example {       static void heapSort(int[] arr, int n) {         ... Read More

Insertion Sort in C#

Arjun Thakur
Updated on 26-Jun-2020 14:30:08

5K+ Views

Insertion Sort is a sorting algorithm that takes an element at a time and inserts it in its correct position in the array. This process is continued until the array is sorted.A program that demonstrates insertion sort in C# is given as follows.Example Live Demousing System; namespace InsertionSortDemo {    class Example {       static void Main(string[] args) {          int[] arr = new int[10] { 23, 9, 85, 12, 99, 34, 60, 15, 100, 1 };          int n = 10, i, j, val, flag;          Console.WriteLine("Insertion Sort");   ... Read More

Selection Sort program in C#

Chandu yadav
Updated on 26-Jun-2020 14:32:38

7K+ Views

Selection Sort is a sorting algorithm that finds the minimum value in the array for each iteration of the loop. Then this minimum value is swapped with the current array element. This procedure is followed until the array is sorted.A program that demonstrates selection sort in C# is given as follows.Example Live Demousing System; public class Example {    static void Main(string[] args) {       int[] arr = new int[10] { 56, 1, 99, 67, 89, 23, 44, 12, 78, 34 };       int n = 10;       Console.WriteLine("Selection sort");       Console.Write("Initial array ... Read More

How to obtain the highest occurring character in a String using C#?

George John
Updated on 26-Jun-2020 14:33:01

4K+ Views

The highest occurring character in a string is one that occurs most number of times. This can be demonstrated using the following example.String: apples are red The highest occurring character in the above string is e as it occurs 3 times, which is more than the occurrence of any other character.A program that obtains the highest occurring character in a string using C# is given as follows.Example Live Demousing System; namespace charCountDemo {    public class Example {       public static void Main() {          String str = "abracadabra";          int []charCount = ... Read More

C# program to find Intersection of two lists

Samual Sam
Updated on 23-Jun-2020 15:06:18

3K+ Views

To find intersection of two lists in C#, use the Intersect() method.The following is our list 1.List list1 = new List(); list1.Add(2); list1.Add(3); list1.Add(5); list1.Add(7);The following is our list 2.List list2 = new List(); list2.Add(5); list2.Add(4); list2.Add(6); list2.Add(8);The following is the code to find the intersection of two lists in C#.Example Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Demo {    public class Program {       public static void Main(String[] args) {          List list1 = new List();          list1.Add(2);          list1.Add(3);          list1.Add(5); ... Read More

Extracting MAC address using C#

karthikeya Boyini
Updated on 23-Jun-2020 15:06:50

4K+ Views

A MAC address of a device is a media access control address. It is a unique identifier assigned to a network.The MAC address technology is used by many technologies such as Ethernet, Bluetooth, Fibre Channel, etc.Here, we will use the following method to check for all the network interfaces on the computer.NetworkInterface.GetAllNetworkInterfacesFor this, the NetworkInterfaceType Enumeration is also used to specify the type of network interfaces.string addr = ""; foreach (NetworkInterface n in NetworkInterface.GetAllNetworkInterfaces()) {    if (n.OperationalStatus == OperationalStatus.Up) {       addr += n.GetPhysicalAddress().ToString();       break;    } } return addr;Above, we have used the ... Read More

Extension Methods in C#

Samual Sam
Updated on 23-Jun-2020 15:07:24

882 Views

Extension methods are static methods, which are called as if they were instance methods on the extended type. With Extension methods, you can add methods to existing types without even creating a new derived type, recompiling, or modifying the original type.The following is the extension method we have created.public static int myExtensionMethod(this string str) {    return Int32.Parse(str); }Let us see an example wherein we have used extension method.Example Live Demousing System; using System.Text; namespace Program {    public static class Demo {       public static int myExtensionMethod(this string str) {          return Int32.Parse(str);     ... Read More

How do we use a break statement in while loop in C#?

karthikeya Boyini
Updated on 23-Jun-2020 15:08:57

270 Views

The break statement terminates the loop and transfers execution to the statement immediately following the loop.When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop.Let us see an example to learn how to work with break statement in while loop. The following code snippet terminates the loop using break statement.if (a > 15) {    break; }The following is the complete code.Example Live Demousing System; namespace Demo {    class Program {       static void Main(string[] args) {          /* local ... Read More

Advertisements