Karthikeya Boyini has Published 2193 Articles

Singleton Class in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:17:21

3K+ Views

Singleton Class allow for single allocations and instances of data. It has normal methods and you can call it using an instance.To prevent multiple instances of the class, the private constructor is used.Let us see an example −public class Singleton {    static Singleton b = null;    private Singleton() ... Read More

Thread-based parallelism in C#

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:15:20

1K+ Views

In C#, Task parallelism divide tasks. The tasks are then allocated to separate threads for processing. In .NET, you have the following mechanisms to run code in parallel: Thread, ThreadPool, and Task. For parallelism, use tasks in C# instead of Threads.A task will not create its own OS thread, whereas ... Read More

How to find the Sum of two Binary Numbers using C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:13:48

2K+ Views

To find the sum of two binary numbers, firstly set them.val1 = 11110; val2 = 11100;Now call the displaySum() method, which created to display the sumL.sum = displaySum(val1, val2);We have set a new array in the method to display each bit of the binary number.long[] sum = new long[30];Now let ... Read More

How to check if a string is a valid keyword in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:08:25

2K+ Views

To check if a string is a valid keyword, use the IsValidIdentifier method.The IsValidIdentifier method checks whether the entered value is an identifier or not. If it’s not an identifier, then it’s a keyword in C#.Let us see an example, wherein we have set the CodeDomProvider and worked with the ... Read More

How to find the Rank of a given Array in C#?

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 10:03:27

281 Views

To find the rank of an array, use the Rank property.Firstly, declare and initialize an array.int[, ] myArr = new int[3, 3];Now, get the rank.myArr.RankLet us see the complete code −Example Live Demousing System; class Demo {    static void Main() {       int[, ] myArr = new int[3, ... Read More

C# program to find the most frequent element

karthikeya Boyini

karthikeya Boyini

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

1K+ Views

Let’s say our string is −String s = "HeathLedger!";Now create a new array.int []cal = new int[maxCHARS];Create a new method and pass both the string and the new array in it. Find the maximum occurrence of a character.static void calculate(String s, int[] cal) {    for (int i = 0; ... Read More

C# Program to replace a special character from a String

karthikeya Boyini

karthikeya Boyini

Updated on 22-Jun-2020 09:57:38

6K+ Views

Let’s say our string is −string str = "abcd$ef$gh";To replace the special character, use the Replace() method.string res = str.Replace('$', 'k');The following is the complete code to replace character from a string −Example Live Demousing System; public class Program {    public static void Main() {       string str ... Read More

How to find the first 10 characters of a string in C#?

karthikeya Boyini

karthikeya Boyini

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

15K+ Views

To get the first 10 characters, use the substring() method.Let’s say the following is our string −string str = "Cricket is a religion in India!";Now to get the first 10 characters, set the value 10 in the substring() method as shown below −string res = str.Substring(0, 10);Let us see the ... Read More

Find the Sum of two Binary Numbers without using a method in C#?

karthikeya Boyini

karthikeya Boyini

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

283 Views

First, declare and initialize two variables with the binary numbers.val1 = 11010; val2 = 10100; Console.WriteLine("Binary one: " + val1); Console.WriteLine("Binary two: " + val2);To get the sum, loop until both the value are 0.while (val1 != 0 || val2 != 0) {    sum[i++] = (val1 % 10 ... Read More

C# program to clone or copy a list

karthikeya Boyini

karthikeya Boyini

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

439 Views

To copy or clone a C# list, firstly set a list.List < string > myList = new List < string > (); myList.Add("One"); myList.Add("Two");Now declare a string array and use the CopyTo() method to copy.string[] arr = new string[10]; myList.CopyTo(arr);Let us see the complete code to copy a list into ... Read More

Advertisements