How to find the length and rank of a jagged array in C#?

Ankith Reddy
Updated on 22-Jun-2020 10:06:48

440 Views

Firstly, set a jagged array.int[][] arr = new int[][] {    new int[] {       0,       0    }, new int[] {       1,       2    },    new int[] {       2,       4    }, new int[] {       3,       6    }, new int[] {       4,       8    } };Now, use the GetLowerBound(), GetUpperBound() and Rank property to get the lenth and rank of the array as shown in the following code ... Read More

Traditional Computing vs Mobile Computing

Kristi Castro
Updated on 22-Jun-2020 10:05:26

2K+ Views

Mobile Computing deals with human computer interaction using mobile devices. It contains mobile hardware and software as well as mobile computing devices. A mobile computing infrastructure usually uses ad-hoc networks and communication protocols. This is considerably different than a traditional computing structure as it uses fixed topology and protocols.An image describing mobile computing architecture is as follows −As seen above, the mobile computing architecture contains various mobile devices such as mobile phones, mobile tablets, laptops etc. These devices are connected to the mobile network which is a part of the internet. All the data is linked to cloud computing data ... Read More

How to find the product of 2 numbers using recursion in C#?

Arjun Thakur
Updated on 22-Jun-2020 10:04:30

276 Views

Firstly, set the two numbers to be multiplied.val1 = 10; val2 = 20;Now cal the method to find the product.product(val1, val2);Under the product method, a recursive call will get you the product.val1 + product(val1, val2 – 1)Let us see the complete code to find the product of 2 numbers using recusion.Exampleusing System; class Calculation {    public static void Main() {       int val1, val2, res;       // the two numbers       val1 = 10;       val2 = 20;       // finding product       Demo d = new ... Read More

How to find the Rank of a given Array in C#?

karthikeya Boyini
Updated on 22-Jun-2020 10:03:27

319 Views

To find the rank of an array, use the Rank property.Firstly, declare and initialize an array.int[,] myArr = new int[3,3];Now, get the rank.myArr.RankLet us see the complete code −Example Live Demousing System; class Demo {    static void Main() {       int[,] myArr = new int[3,3];       Console.WriteLine("Rank of Array : " + myArr.Rank);    } }OutputRank of Array : 2

Hash Functions and Hash Tables

Alex Onsman
Updated on 22-Jun-2020 10:03:08

14K+ Views

Hashing is the process of generating a value from a text or a list of numbers using a mathematical function known as a hash function.There are many hash functions that use numeric numeric or alphanumeric keys. Different hash functions are given below:Hash FunctionsThe following are some of the Hash Functions −Division MethodThis is the easiest method to create a hash function. The hash function can be described as −h(k) = k mod nHere, h(k) is the hash value obtained by dividing the key value k by size of hash table n using the remainder. It is best that n is ... Read More

How to find Volume and Surface Area of a Sphere using C#?

Samual Sam
Updated on 22-Jun-2020 10:00:28

408 Views

For volume and surface area of a sphere, firstly declare a variable with the value of radius.int r = 15;Get the volume f the sphere.// calculating volume of sphere cal_volume = (4.0 / 3) * (22 / 7) * r * r * r;Now the surface area of the sphere is calculated −cal_area = 4 * (22 / 7) * r * r;Let us see the complete code −Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(string[] args) {       double cal_area, cal_volume, r;       // radius       ... Read More

How to find the size of a list in C#?

Chandu yadav
Updated on 22-Jun-2020 09:59:59

3K+ Views

Declare and initialize a list.var products = new List (); products.Add("Accessories"); products.Add("Clothing"); products.Add("Footwear");To get the size, use the Capacity property.products.CapacityNow let us see the complete code to find the size of a list.Example Live Demousing System; using System.Collections.Generic; public class Demo {    public static void Main(string[] args) {       var products = new List ();       products.Add("Accessories");       products.Add("Clothing");       products.Add("Footwear");       Console.WriteLine("Our list....");       foreach(var p in products) {          Console.WriteLine(p);       }       Console.WriteLine("Size of list = " + products.Capacity);    } }OutputOur list.... Accessories Clothing Footwear Size of list = 4

C# program to find the most frequent element

karthikeya Boyini
Updated on 22-Jun-2020 09:58:31

1K+ Views

Let’s say our string is −String s = "HeathLedger!";Now create a new array.int []cal = new int[maxCHARS];Create a new method and pass both the string and the new array in it. Find the maximum occurrence of a character.static void calculate(String s, int[] cal) {    for (int i = 0; i < s.Length; i++)    cal[s[i]]++; }Let us see the complete code −Example Live Demousing System; class Demo {    static int maxCHARS = 256;    static void calculate(String s, int[] cal) {       for (int i = 0; i < s.Length; i++)       cal[s[i]]++;    } ... Read More

Declare a const array in C#

Ankith Reddy
Updated on 22-Jun-2020 09:57:59

13K+ Views

In C#, use readonly to declare a const array.public static readonly string[] a = { "Car", "Motorbike", "Cab" };In readonly, you can set the value at runtime as well unlike const.Another alternative of achieving what we saw above −public ReadOnlyCollection a { get { return new List { "Car", "Motorbike", "Cab" }.AsReadOnly();}} .NET framework 4.5 brings an improvement to what we saw −public ReadOnlyCollection a { get; } = new ReadOnlyCollection( new string[] { "Car", "Motorbike", "Cab" } );

C# Program to replace a special character from a String

karthikeya Boyini
Updated on 22-Jun-2020 09:57:38

6K+ Views

Let’s say our string is −string str = "abcd$ef$gh";To replace the special character, use the Replace() method.string res = str.Replace('$', 'k');The following is the complete code to replace character from a string −Example Live Demousing System; public class Program {    public static void Main() {       string str = "abcd$ef$gh";       Console.WriteLine("Initial string = " + str);       string res = str.Replace('$', 'k');       // after replacing       Console.WriteLine("Replaced string = " + res.ToString());    } }OutputInitial string = abcd$ef$gh Replaced string = abcdkefkgh

Advertisements