Server Side Programming Articles

Page 796 of 2109

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

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 462 Views

A jagged array in C# is an array of arrays where each sub-array can have different lengths. Unlike multi-dimensional arrays, jagged arrays provide flexibility in storing varying amounts of data in each row. To find the length and rank of a jagged array, you can use the Length property, GetLowerBound() and GetUpperBound() methods, and the Rank property. Syntax Following is the syntax for declaring a jagged array − dataType[][] arrayName = new dataType[rows][]; Following are the methods and properties to find length and rank − arrayName.Length ...

Read More

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

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 367 Views

The rank of an array in C# refers to the number of dimensions it has. A one-dimensional array has a rank of 1, a two-dimensional array has a rank of 2, and so on. To find the rank of any array, use the Rank property. Syntax Following is the syntax to get the rank of an array − arrayName.Rank Return Value The Rank property returns an int value representing the number of dimensions in the array. Using Rank Property with Different Array Types Example 1: Single-Dimensional Array using System; ...

Read More

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

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 302 Views

Finding the product of two numbers using recursion in C# is an interesting approach that demonstrates how multiplication can be implemented using only addition and recursive function calls. Instead of using the standard multiplication operator, we build the product by repeatedly adding one number to itself. How Recursive Multiplication Works The concept is based on the mathematical principle that multiplication is repeated addition. For example, 5 × 3 = 5 + 5 + 5. In recursion, we add the first number to itself and reduce the second number by 1 until it reaches zero. ...

Read More

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

Samual Sam
Samual Sam
Updated on 17-Mar-2026 446 Views

To find the volume and surface area of a sphere using C#, we need to apply mathematical formulas that use the sphere's radius. A sphere is a perfectly round three-dimensional object where every point on its surface is equidistant from its center. Sphere Formulas r Sphere Formulas Surface Area = 4πr² Volume = (4/3)πr³ where r = radius of the sphere Formulas The mathematical formulas for a sphere are − ...

Read More

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

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 4K+ Views

A List in C# is a dynamic collection that can grow or shrink in size. To determine the size of a list, you can use two different properties: Count (for the number of actual elements) and Capacity (for the total allocated space). Syntax To get the number of elements in a list − listName.Count To get the total capacity (allocated space) of a list − listName.Capacity Understanding Count vs Capacity Count vs Capacity Count Number of actual ...

Read More

C# program to find the most frequent element

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

Finding the most frequent element in a string is a common programming problem that involves counting the occurrences of each character and determining which appears most often. In C#, this can be efficiently solved using an array to track character frequencies. Syntax Following is the basic approach to count character frequencies − int[] frequency = new int[256]; // ASCII character set for (int i = 0; i < str.Length; i++) { frequency[str[i]]++; } Using Array-Based Frequency Counting The most straightforward approach uses an integer array where each index corresponds ...

Read More

Declare a const array in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 13K+ Views

In C#, you cannot directly declare a const array because arrays are reference types and const fields must be compile-time constants. However, you can achieve similar behavior using readonly fields or ReadOnlyCollection to create immutable arrays. Syntax Following is the syntax for declaring a readonly array − public static readonly DataType[] arrayName = { value1, value2, value3 }; Following is the syntax for using ReadOnlyCollection − public static readonly ReadOnlyCollection arrayName = new ReadOnlyCollection(new DataType[] { value1, value2, value3 }); Using readonly Static Arrays ...

Read More

How to find the size of a variable without using sizeof in C#?

Syed Javed
Syed Javed
Updated on 17-Mar-2026 2K+ Views

In C#, the sizeof operator is commonly used to determine the size of a value type in bytes. However, there are alternative approaches to find the size of a variable without using sizeof, such as using the BitConverter class or Marshal.SizeOf method. Syntax Using sizeof operator − int size = sizeof(dataType); Using BitConverter.GetBytes() method − byte[] dataBytes = BitConverter.GetBytes(variable); int size = dataBytes.Length; Using Marshal.SizeOf() method − int size = Marshal.SizeOf(typeof(dataType)); Using BitConverter.GetBytes() Method The BitConverter.GetBytes() method converts a value to its byte array representation. ...

Read More

Find frequency of each word in a string in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 877 Views

Finding the frequency of each word in a string in C# involves splitting the string into individual words and counting their occurrences. This is a common text processing task useful for data analysis, word clouds, and text mining applications. Using Dictionary for Word Frequency The most efficient approach is to use a Dictionary to store words as keys and their frequencies as values − using System; using System.Collections.Generic; class WordFrequency { public static void Main() { string text = "apple banana apple orange banana apple"; ...

Read More

How to find the Sum of two Binary Numbers using C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 2K+ Views

Adding two binary numbers in C# involves performing binary arithmetic bit by bit, just like manual addition but working in base-2. The process includes handling carry operations when the sum of bits exceeds 1. Binary addition follows simple rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 10 (which means 0 with a carry of 1). Syntax Following is the basic approach for binary addition − // Extract rightmost bits bit1 = val1 % 10; bit2 = val2 % 10; // Calculate ...

Read More
Showing 7951–7960 of 21,090 articles
« Prev 1 794 795 796 797 798 2109 Next »
Advertisements