Samual Sam has Published 2492 Articles

Jagged Array in C#

Samual Sam

Samual Sam

Updated on 20-Jun-2020 14:58:22

255 Views

A Jagged array is an array of arrays. You can declare a jagged array named points of type int as −int [][] points;Let us now see how to initialize it −int[][] points = new int[][]{new int[]{10, 5}, new int[]{30, 40}, new int[]{70, 80}, new int[]{ 60, 70 }};Access the jagged ... Read More

How to define the rank of an array in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 14:55:53

309 Views

To find the number of dimensions of an array, use the Array Rank property. This is how you can define it −arr.RankHere, arr is our array −int[, ] arr = new int[3, 4];If you want to get the rows and columns it has, then uses the GetLength property −arr.GetLength(0); arr.GetLength(1);The ... Read More

Static class in C#

Samual Sam

Samual Sam

Updated on 20-Jun-2020 14:49:07

606 Views

The C# static class cannot be instantiated and can only have only static members. The static class in C# is sealed and cannot contain instance constructors.The following is an example with static class and static members −Example Live Demousing System; public static class Demo {    public static float PI ... Read More

Threads in C#

Samual Sam

Samual Sam

Updated on 20-Jun-2020 14:43:40

530 Views

A thread is defined as the execution path of a program. Each thread defines a unique flow of control. If your application involves complicated and time-consuming operations, then it is often helpful to set different execution paths or threads, with each thread performing a particular job.The life cycle of a ... Read More

How to write single-line comments in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 14:42:22

172 Views

If you want to add a comment that restricts itself to a single line, then use the single-line comments −// variable int i = 20;The following is a sample C# program showing how to add single-line comments −Example Live Demousing System; namespace Demo {    class Program {     ... Read More

How to write multi-line comments in C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 14:40:21

709 Views

The comments that spread more than one line is called multi-line comments −/* The following is a multi-line Comment In C# /*The /*...*/ is ignored by the compiler and it is put to add comments in the program.The following is a sample C# program showing how to add MULTI-line comments ... Read More

C# program to print all the numbers divisible by 3 and 5 for a given number

Samual Sam

Samual Sam

Updated on 20-Jun-2020 14:36:21

5K+ Views

To print the numbers divisible by 3 and 5, use the && operator and check two conditions −f (num % 3 == 0 && num % 5 == 0) {}If the above condition is true, that would mean the number is divisible by 3 as well as 5.The following is ... Read More

Write a C# function to print nth number in Fibonacci series?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 14:25:20

509 Views

Set the following, if the nth number is let’s say num −int n = num- 1; int[] val = new int[n + 1];Then set the default Fibonacci numbers on the first and second position −val[0]= 0; val[1]= 1;Loop through i=2 to i

How to calculate the power exponent value using C#?

Samual Sam

Samual Sam

Updated on 20-Jun-2020 14:18:25

1K+ Views

To calculate the power exponent value, use the Math.pow() method.Here, n is the number and p is the power −double res = Math.Pow(n, p);The following is the complete code −Example Live Demousing System; class Program {    static void Main() {       double n, p;       n ... Read More

What is the Values property of SortedList class in C#?

Samual Sam

Samual Sam

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

62 Views

Firstly, declare the SortedList class −SortedList list = new SortedList();Now add the values −list.Add("S1", "Wallets"); list.Add("S2", "Sunglasses"); list.Add("S3", "Backpacks");The following is the code to work with Values property of SortedList class −Example Live Demousing System; using System.Collections; namespace Demo {    class Program {       static void Main(string[] ... Read More

Advertisements