Csharp Articles

Page 85 of 196

How to perform Division of Exponents of Same Base using C#?

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 255 Views

Firstly, set the base −double n = 10;Now set the two exponents for division −double e1 = 10; double e2 = 8;Let us see the complete code to get the result of division of exponents of the same base.Exampleusing System; class Demo {    static void Main() {       double res, n, e1, e2;       n = 10;       e1 = 10;       e2 = 8;       res = e1 - e2;       Console.WriteLine("Result = {0}^{1} : {2}", n, res, Math.Pow(n, res));       Console.ReadLine();    } }outputResult = 10^2 : 100

Read More

Print a 2 D Array or Matrix in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

First, set a two-dimensional array.int[, ] arr = new int[10, 10];Now, get the elements from the user −for (i = 0; i < m; i++) {    for (j = 0; j < n; j++) {       arr[i, j] = Convert.ToInt16(Console.ReadLine());    } }Let us see the complete example to display the matrix.Exampleusing System; using System.Linq; class Demo {    static void Main() {       int m, n, i, j;       // rows and columns of the matrix+       m = 2;       n = 2; ...

Read More

Large Fibonacci Numbers in C#

Chandu yadav
Chandu yadav
Updated on 11-Mar-2026 540 Views

To display large Fibonacci numbers, try the following login and code.Here, we have set the value of n as the series. Set it to get the Fibonacci number. Below, we have set it to 100 to get the first 100 Fibonacci numbers.Since the first two numbers in a Fibonacci series are 0 and 1. Therefore, we will set the first two values.int val1 = 0, val2 = 1;The following is the complete code to display large Fibonacci numbers.Exampleusing System; public class Demo {    public static void Main(string[] args) {       int val1 = 0, val2 = 1, ...

Read More

Lambda Expressions in C#

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 798 Views

A lambda expression in C# describes a pattern.Lambda Expressions has the token => in an expression context. This is read as “goes to” operator and used when a lambda expression is declared.Here, we are finding the first occurrence of the element greater than 50 from a list.list.FindIndex(x => x > 50);Above the token => is used. The same is shown below −Exampleusing System; using System.Collections.Generic; class Demo {    static void Main() {       List list = new List { 44, 6, 34, 23, 78 };       int res = list.FindIndex(x => x > 50);       Console.WriteLine("Index: "+res);    } }OutputIndex: 4

Read More

How to print the first ten Fibonacci numbers using C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 840 Views

For displaying the first ten numbers, firstly set the first two numbers.int val1 = 0, val2 = 1;Now, use a for loop from 2 to 10, to display first ten Fibonacci numbers −for(i=2;i

Read More

How to print one dimensional array in reverse order?

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 599 Views

Firstly, declare and initialize one dimensional array.int[] arr = { 35, 12, 66, 90, 34, 2, 64 };Now, use the following to reverse −Array.Reverse(arr);The following is the complete code to reverse a one-dimensional array;Exampleusing System; class Demo {    static void Main() {       int[] arr = { 76, 12, 66, 90, 34, 2, 64 };       // Initial Array       Console.WriteLine("Original Array= ");       foreach (int i in arr) {          Console.WriteLine(i);       }       // Reverse Array       Array.Reverse(arr);       Console.WriteLine("Reversed Array= ");       foreach (int j in arr) {          Console.WriteLine(j);       }       Console.ReadLine();    } }OutputOriginal Array= 76 12 66 90 34 2 64 Reversed Array= 64 2 34 90 66 12 76

Read More

How to remove an empty string from a list of empty strings in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

Firstly, set a list with empty string as elements.List myList = new List() {    " ",    " ",    " " };Now let us remove one empty element using index.myList.RemoveAt(0);Exampleusing System; using System.Collections.Generic; using System.Linq; class Program {    static void Main() {       List myList = new List() {          " ",          " ",          " "       };       Console.Write("Initial list with empty strings...");       foreach (string list in myList) {          Console.WriteLine(list); ...

Read More

How to find a number using Pythagoras Theorem using C#?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 625 Views

Firstly, set the first two numbers −double val1, val2; val1 = 10; val2 = 5;Now use the Math.Sqrt function to use Pythagoras Theorem.res = Math.Sqrt(val1 * val1 + val2 * val2);Exampleusing System; public class Program {    public static void Main(string[] args) {       double val1, val2, res;       val1 = 10;       val2 = 5;       res = Math.Sqrt(val1 * val1 + val2 * val2);       Console.WriteLine("Result = {0}", res);       Console.ReadLine();    } }OutputResult = 11.1803398874989

Read More

How to find a number in a string in C#?

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 475 Views

To find a number in a string, use Regular Expressions.We have set the Regex pattern to get number from a string.Regex r = new Regex(@"\d+");Now, use Match class in C# to set the string.Match m = r.Match("Welcome! We are open 365 days in a year!");Use the Success property now to display the result if number is found in the string as shown in the following complete code −Exampleusing System; using System.Text.RegularExpressions; class Demo {    static void Main() {       Regex r = new Regex(@"\d+");       Match m = r.Match("Welcome! We are open 365 ...

Read More

How to find date difference in C#?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 155 Views

To find the difference between two dates in C#, you need to first set two dates to be compared using the DateTime object. We will use the DateTime class in C#.Date 1DateTime date1 = new DateTime(2018, 09, 15); Console.WriteLine("Date 1 : {0}", date1);Date 2DateTime date2 = new DateTime(2018, 09, 28); Console.WriteLine("Date 2 : {0}", date2);Now let us compare both the dates in C#. The following is an example to compare dates in C#.Exampleusing System; namespace Program {    class Demo {       static int Main() {          DateTime date1 = new DateTime(2018, 09, 15);   ...

Read More
Showing 841–850 of 1,951 articles
« Prev 1 83 84 85 86 87 196 Next »
Advertisements