Samual Sam has Published 2492 Articles

C# program to convert a list of characters into a string

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:04:00

683 Views

Firstly, declare the character array and set the value of each character −char[] ch = new char[5]; ch[0] = 'H'; ch[1] = 'e'; ch[2] = 'l'; ch[3] = 'l'; ch[4] = 'o';Now, use the string class constructor and create a new string from the above array of characters −string ... Read More

C# program to count occurrences of a word in string

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:02:48

3K+ Views

Set the string first −string str = "Hello World! Hello!";Now check the string for the occurrences of a word “Hello’ and loop through −while ((a = str1.IndexOf(pattern, a)) != -1) {    a += pattern.Length;    count++; }ExampleYou can try to run the following code to count occurrences of a ... Read More

C# Program to Convert Binary to Decimal

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:01:36

3K+ Views

Firstly, set the binary value −int num = 101;Now assign the binary to a new variable −binVal = num;Till the value is greater than 0, loop through the binary number and base value like this, while (num > 0) {    rem = num % 10;    decVal = decVal ... Read More

C# Bitwise and Bit Shift Operators

Samual Sam

Samual Sam

Updated on 19-Jun-2020 09:00:12

3K+ Views

Bitwise operator works on bits and performs bit by bit operation.The Bitwise operators supported by C# are listed in the following table. Assume variable A holds 60 and variable B holds 13 −OperatorDescriptionExample&Bitwise AND Operator copies a bit to the result if it exists in both operands.(A & B) = ... Read More

C# Example for MultiLevel Inheritance

Samual Sam

Samual Sam

Updated on 19-Jun-2020 08:58:22

4K+ Views

Multilevel Inheritance occurs when a derived class is formed from another derived class.Grandfather, father, and son are the perfect example to represent Multilevel Inheritance in C# −ExampleThe following is an example stating the usage of multilevel inheritance in C#.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo { ... Read More

C# factorial

Samual Sam

Samual Sam

Updated on 19-Jun-2020 08:57:13

2K+ Views

To calculate factorial in C#, you can use while loop and loop through until the number is not equal to 1.Here n is the value for which you want the factorial −int res = 1; while (n != 1) {    res = res * n;    n = n ... Read More

C# Language advantages and applications

Samual Sam

Samual Sam

Updated on 19-Jun-2020 08:54:56

4K+ Views

C# is a modern, general-purpose, object-oriented programming language developed by Microsoft and approved by European Computer Manufacturers Association (ECMA) and International Standards Organization (ISO).C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows the use of various high-level languages on different ... Read More

C# program to check for URL in a String

Samual Sam

Samual Sam

Updated on 19-Jun-2020 08:53:45

2K+ Views

Use the StartWith() method in C# to check for URL in a String.Let us say our input string is −string input = "https://example.com/new.html";Now we need to check for www or non-www link. For this, use the if statement in C# −if (input.StartsWith("https://www.example.com") || input.StartsWith("https://example.com")) { }ExampleYou can try to run ... Read More

C# program to check if there are K consecutive 1’s in a binary number

Samual Sam

Samual Sam

Updated on 19-Jun-2020 08:37:46

213 Views

To check for consecutive 1’s in a binary number, you need to check for 0 and 1.Firstly, set a bool array for 0s and 1s i.e. false and true −bool []myArr = {false, true, false, false, false, true, true, true};For 0, set the count to 0 −if (myArr[i] == false) ... Read More

C# Program to Check status of Current Thread

Samual Sam

Samual Sam

Updated on 19-Jun-2020 08:37:16

2K+ Views

To check the status of the current thread in C#, use the IsAlive property.Firstly, use the currentThread property to display information about a thread −Thread thread = Thread.CurrentThread;Now use the thread.IsAlive property to check the status of the thread −thread.IsAliveExampleLet us see the complete code to check the status of current ... Read More

Advertisements