Samual Sam has Published 2310 Articles

C# Program to Convert Binary to Decimal

Samual Sam

Samual Sam

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

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

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

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

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

294 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

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

C# and Multiple Inheritance

Samual Sam

Samual Sam

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

5K+ Views

Multiple Inheritance isn’t supported in C#. To implement multiple inheritances, use Interfaces.Here is our interface PaintCost in class Shape −public interface PaintCost {    int getCost(int area); }The shape is our base class whereas Rectangle is the derived class −class Rectangle : Shape, PaintCost {    public int getArea() { ... Read More

C# Example for Hierarchical Inheritance

Samual Sam

Samual Sam

Updated on 19-Jun-2020 08:32:41

3K+ Views

More than one class is inherited from the base class in Hierarchical Inheritance.In the example, our base class is Father −class Father {    public void display() {       Console.WriteLine("Display...");    } }It has Son and Daughter as the derived class. Let us how to add a derived ... Read More

Advertisements