Programming Articles

Page 101 of 2547

How are values assigned to arrays in C#?

George John
George John
Updated on 17-Mar-2026 187 Views

Declaring an array does not initialize the array in memory. When the array variable is initialized, you can assign values to the array using several different approaches in C#. Array is a reference type, so you need to use the new keyword to create an instance of the array. There are multiple ways to assign values to arrays, each with its own syntax and use cases. Syntax Following is the syntax for declaring and initializing arrays − // Declaration with size datatype[] arrayName = new datatype[size]; // Assignment using index arrayName[index] = value; ...

Read More

How to get the nth value of a Fibonacci series using recursion in C#?

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

The Fibonacci series is a sequence where each number is the sum of the two preceding numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21... In C#, we can use recursion to calculate the nth Fibonacci number by breaking the problem into smaller subproblems. Recursion works by having the method call itself with reduced parameters until it reaches a base case. For Fibonacci, the base cases are F(0) = 0 and F(1) = 1. Syntax Following is the syntax for a recursive Fibonacci method − public int Fibonacci(int n) { if ...

Read More

C# Program to return a collection with repeated elements

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 388 Views

To return a collection with repeated elements in C#, use the Enumerable.Repeat method from the System.Linq namespace. This method creates a sequence that contains one repeated value a specified number of times. Syntax Following is the syntax for Enumerable.Repeat method − public static IEnumerable Repeat(TResult element, int count) Parameters element − The value to be repeated in the result sequence. count − The number of times to repeat the value in the generated sequence. Return Value Returns an IEnumerable that contains a repeated value. ...

Read More

How to use Remove, RemoveAt, RemoveRange methods in C# list collections?

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

C# provides several methods to remove elements from List collections. The Remove() method removes the first occurrence of a specific value, RemoveAt() removes an element at a specific index, and RemoveRange() removes multiple consecutive elements. Syntax Following is the syntax for the three removal methods − // Remove by value (first occurrence) bool Remove(T item) // Remove by index void RemoveAt(int index) // Remove range of elements void RemoveRange(int index, int count) Parameters Remove(T item): The item to remove from the list. Returns true if item is found and removed. ...

Read More

C# program to separate joined strings in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 106 Views

In C#, you can join string arrays into a single string using string.Join() and then separate the joined string back into individual elements using the Split() method. This is useful when you need to manipulate strings by combining them temporarily and then extracting the original components. Syntax Following is the syntax for joining strings − string joinedString = string.Join(separator, stringArray); Following is the syntax for separating joined strings − string[] separatedArray = joinedString.Split(separator); Parameters separator − The character or string used to separate elements during joining and ...

Read More

Convert.ToInt32 Method in C#

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

The Convert.ToInt32() method in C# converts a specified value to a 32-bit signed integer. This method provides type conversion from various data types including string, double, float, decimal, and bool to int. The method uses rounding to nearest even (banker's rounding) when converting floating-point numbers, and throws exceptions for invalid conversions like null strings or out-of-range values. Syntax Following are the common overloads of Convert.ToInt32() method − Convert.ToInt32(object value) Convert.ToInt32(string value) Convert.ToInt32(double value) Convert.ToInt32(bool value) Parameters value − The value to convert to a 32-bit signed integer. Return Value ...

Read More

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

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

The Item property of the SortedList class in C# gets and sets the value associated with a specific key in the SortedList. It allows you to access and modify elements using the indexer syntax [key], making SortedList operations intuitive and similar to working with arrays or dictionaries. The Item property can also be used to add new elements directly. If the key does not exist, it creates a new key-value pair. If the key already exists, it overwrites the existing value with the new one. Syntax Following is the syntax for using the Item property − ...

Read More

Math Class Fields with Examples in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 205 Views

The Math class in C# provides essential mathematical constants through predefined fields. The two most commonly used fields are Math.E (Euler's number) and Math.PI (pi), which represent fundamental mathematical constants used in various calculations. These fields are declared as public const double, making them accessible throughout your application without needing to instantiate the Math class. Math.E Field The Math.E field represents Euler's number, which is the natural logarithmic base. This constant is approximately equal to 2.718281828 and is frequently used in exponential and logarithmic calculations. Syntax public const double E = 2.71828182845905; ...

Read More

How to determine if the string has all unique characters using C#?

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

To determine if a string has all unique characters, you need to check if any character appears more than once. This can be accomplished using several approaches in C#, from simple nested loops to more efficient data structures like HashSet. Using Nested Loop Approach The basic approach involves comparing each character with every other character in the string − using System; class Program { public static bool HasUniqueCharacters(string val) { for (int i = 0; i < val.Length - 1; i++) { ...

Read More

Bool Array in C#

George John
George John
Updated on 17-Mar-2026 10K+ Views

A bool array in C# is used to store multiple boolean values (true and false) in a single collection. Boolean arrays are useful for tracking states, flags, or conditions across multiple elements. Syntax Following are the different ways to declare and initialize a bool array − // Declaration with size bool[] arrayName = new bool[size]; // Declaration with initialization bool[] arrayName = {true, false, true}; // Using new keyword with values bool[] arrayName = new bool[] {true, false, true}; Creating and Initializing Bool Arrays Method 1: Declaration with Size and Assignment ...

Read More
Showing 1001–1010 of 25,467 articles
« Prev 1 99 100 101 102 103 2547 Next »
Advertisements