Found 2628 Articles for Csharp

Compare two strings lexicographically in C#

karthikeya Boyini
Updated on 19-Jun-2020 12:11:36

2K+ Views

To compare strings in C#, use the compare() method. It compares two strings and returns the following integer values −If str1 is less than str2, it returns -1. If str1 is equal to str2, it returns 0. If str1 is greater than str2, it returns 1.Set the two strings in the String.compare() method and compare them −string.Compare(string1, string2);ExampleYou can try to run the following code to compare two strings in C#.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {    class MyApplication {       static void Main(string[] args) {         ... Read More

Common Language Runtime (CLR) in C#.NET

Samual Sam
Updated on 19-Jun-2020 12:12:53

5K+ Views

Common Language Runtime (CLR) manages the execution of .NET programs. The just-in-time compiler converts the compiled code into machine instructions. This is what the computer executes.The services provided by CLR include memory management, exception handling, type safety, etc.Let us see the features of Common Language Runtime (CLR) in C#:ComponentsComponents in other languages can be easily worked upon with CLR.ThreadingThe CLR provides support for threads to create multithreaded applications.Class Library SupportIt has built-in types and libraries for assemblies, threading, memory management, etc.DebuggingCLR makes code debugging easier.Garbage CollectionIt provides automatic garbage collection in C#.

C# program to find the sum of digits of a number using Recursion

karthikeya Boyini
Updated on 19-Jun-2020 12:13:42

235 Views

Let’s say we have set the number for which we will find the sum of digits −int val = 789; Console.WriteLine("Number:", val);The following will find the sum of digits by entering the number and checking it recursively −public int addFunc(int val) {    if (val != 0) {       return (val % 10 + addFunc(val / 10));    } else {       return 0;    } }ExampleThe following is our code to find the sum of digits of a number using Recursion in C#.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {   ... Read More

C# Program to find whether the Number is Divisible by 2

Samual Sam
Updated on 19-Jun-2020 12:14:32

6K+ Views

If the remainder of the number when it is divided by 2 is 0, then it would be divisible by 2.Let’s say our number is 5, we will check it using the following if-else −// checking if the number is divisible by 2 or not if (num % 2 == 0) {    Console.WriteLine("Divisible by 2 "); } else {    Console.WriteLine("Not divisible by 2"); }ExampleThe following is an example to find whether the number is divisible by 2 or not.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {    class MyApplication {       static ... Read More

C# Program to Create a Thread Pool

karthikeya Boyini
Updated on 19-Jun-2020 11:36:47

487 Views

For a thread pool, create more than two functions and queue methods for execution.Firstly, create a method like −public void one(object o) {    for (int i = 0; i

C# Program to create a Simple Thread

Samual Sam
Updated on 19-Jun-2020 11:38:02

433 Views

To create a thread, I have created a function −public void myThread() {    for (int i = 0; i < 3; i++) {       Console.WriteLine("My Thread");    } }The above function is called to create a thread and a new ThreadStart delegate is created −Demo d = new Demo(); Thread thread = new Thread(new ThreadStart(d.myThread));ExampleCreate a simple thread using the following code.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; class Demo {    public void myThread() {       for (int i = 0; i < 3; i++) {         ... Read More

C# program to find the maximum of three numbers

karthikeya Boyini
Updated on 19-Jun-2020 11:38:44

10K+ Views

Firstly, let’s set the three numbers −int num1, num2, num3; // set the value of the three numbers num1 = 10; num2 = 20; num3 = 50;Now check the first number with the second number. If num1 > num2, then check num1 with num3. If num1 is greater than num3, that would mean the largest number is num1.ExampleYou can try to run the following code to find the maximum of three numbers.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {    class MyApplication {       static void Main(string[] args) {          int ... Read More

C# program to split and join a string

Samual Sam
Updated on 19-Jun-2020 11:39:37

2K+ Views

To split and join a string in C#, use the split() and join() method. Let us say the following is our string −string str = "This is our Demo String";To split the string, we will use the split() method −var arr = str.Split(' ');Now to join, use the join() method and join rest of the string. Here, we have skipped the part of the string using the skip() method −string rest = string.Join(" ", arr.Skip(1));ExampleYou can try to run the following code in C# to split and join a string.Live Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo ... Read More

C# Program to perform Celsius to Fahrenheit Conversion

karthikeya Boyini
Updated on 19-Jun-2020 11:41:12

6K+ Views

Firstly, set the Celsius temperature −double celsius = 36; Console.WriteLine("Celsius: " + celsius);Now convert it into Fahrenheit:fahrenheit = (celsius * 9) / 5 + 32;You can try to run the following code to convert Celsius to Fahrenheit.ExampleLive Demousing System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Demo {    class MyApplication {       static void Main(string[] args) {          double fahrenheit;          double celsius = 36;          Console.WriteLine("Celsius: " + celsius);          fahrenheit = (celsius * 9) / 5 + 32;          Console.WriteLine("Fahrenheit: " + fahrenheit);          Console.ReadLine();       }    } }OutputCelsius: 36 Fahrenheit: 96.8

C# Program to perform all Basic Arithmetic Operations

Samual Sam
Updated on 19-Jun-2020 11:44:15

7K+ Views

Basic Arithmetic Operators in C#, include the following −OperatorDescription+Adds two operands-Subtracts the second operand from the first*Multiplies both operands/Divides the numerator by de-numerator%Modulus Operator and remainder of after an integer division++Increment operator increases integer value by one--Decrement operator decreases integer value by oneTo add, use the Addition Operator −num1 + num2;In the same way, it works for Subtraction, Multiplication, Division, and other operators.ExampleLet us see a complete example to learn how to implement Arithmetic operators in C#.Live Demousing System; namespace Sample {    class Demo {       static void Main(string[] args) {          int num1 ... Read More

Advertisements