Samual Sam has Published 2310 Articles

How to find the average of elements of an integer array in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 09:56:58

235 Views

The following is our integer array −int[] myArr = new int[6] {    8,    4,    2,    5,    9,    14 };Firstly, get the length of the array, and loop through the array to find the sum of the elements. After that, divide it with the length.int ... Read More

How to find the product of two binary numbers using C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 09:54:11

608 Views

To find the product of two binary numbers, firstly set them.val1 = 11100; val2 = 10001; Console.WriteLine("Binary one: "+val1); Console.WriteLine("Binary two: "+val2);Now loop through to get the product.while (val2 != 0) {    digit = val2 % 10;    if (digit == 1) {       val1 = ... Read More

Threads and Thread Synchronization in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 09:51:18

930 Views

Using Synchronization, you can synchronize access to resources in multithreaded applications.A mutex can be used to synchronize threads across processes Use it to prevent the simultaneous execution of a block of code by more than one thread at a time.C# lock statement is used to ensure that a block of ... Read More

C# program to check if two lists have at-least one element common

Samual Sam

Samual Sam

Updated on 22-Jun-2020 09:49:07

939 Views

Set the first list.int[] arr1 = {    65,    57,    63,    98 };Now, set the second list.int[] arr2 = {    43,    65,    33,    57 };Let us now see the complete code to check if two lists have common elements using == and < ... Read More

C# program to print unique values from a list

Samual Sam

Samual Sam

Updated on 22-Jun-2020 09:44:45

6K+ Views

Set the list.List < int > list = new List < int > (); list.Add(99); list.Add(49); list.Add(32);To get unique elements.List myList = list.Distinct().ToList();Here is the complete example to display unique values from a list.Example Live Demousing System; using System.Collections.Generic; using System.Linq; public class Demo {    public static void Main() ... Read More

What is the Mutex class in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 09:43:02

2K+ Views

The Mutex class in C# is a synchronization primitive that can also be used for interprocess synchronization.Let us see how to create a new Mutex.private static Mutex m = new Mutex();Let us now see how to initialize a new instance of the Mutex class with a Boolean value.private static Mutex ... Read More

Sorting a String in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 09:41:20

6K+ Views

Firstly, set a string array.string[] values = { "tim", "amit", "tom", "jack", "saurav"};Use the Sort() method to sort.Array.Sort(values);Let us see the complete code −Example Live Demousing System; public class Program {    public static void Main() {       string[] values = { "tim", "amit", "tom", "jack", "saurav"};   ... Read More

C# program to split the Even and Odd integers into different arrays

Samual Sam

Samual Sam

Updated on 22-Jun-2020 09:37:39

2K+ Views

Take two arrays:int[] arr2 = new int[5]; int[] arr3 = new int[5];Now, if the array element gets the remainder 0 on dividing by 2, it is even. Get those elements and add in another array. This loops through the length of the array:if (arr1[i] % 2 == 0) {   ... Read More

C# program to find Largest, Smallest, Second Largest, Second Smallest in a List

Samual Sam

Samual Sam

Updated on 22-Jun-2020 09:31:34

2K+ Views

Set the listvar val = new int[] {    99,    35,    26,    87 };Now get the largest number.val.Max(z => z);Smallest numberval.Min(z => z);Second largest numberval.OrderByDescending(z => z).Skip(1).First();Second smallest numberval.OrderBy(z => z).Skip(1).First();The following is the code −Example Live Demousing System; using System.Linq; public class Program {    public ... Read More

What is abstraction in C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 09:29:18

2K+ Views

Abstraction and encapsulation are related features in object-oriented programming. Abstraction allows making relevant information visible and encapsulation enables a programmer to implement the desired level of abstraction.Abstraction can be achieved using abstract classes in C#. C# allows you to create abstract classes that are used to provide a partial class ... Read More

Advertisements