Samual Sam has Published 2492 Articles

Calculate the execution time of a method in C#

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:09:06

632 Views

Use Stopwatch class to measure time of execution of a method in .NET −Stopwatch s = Stopwatch.StartNew();Now set a function and use the ElapsedMilliseconds property to get the execution time in milliseconds −s.ElapsedMillisecondsLet us see the complete code −Example Live Demousing System; using System.IO; using System.Diagnostics; public class Demo { ... Read More

How to find Volume and Surface Area of a Sphere using C#?

Samual Sam

Samual Sam

Updated on 22-Jun-2020 10:00:28

235 Views

For volume and surface area of a sphere, firstly declare a variable with the value of radius.int r = 15;Get the volume f the sphere.// calculating volume of sphere cal_volume = (4.0 / 3) * (22 / 7) * r * r * r;Now the surface area of the sphere ... Read More

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

148 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

464 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

559 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

669 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

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

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

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

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

Advertisements