C# program to find the index of a word in a string

Ankith Reddy
Updated on 17-Mar-2026 07:04:35

664 Views

Finding the index of a word in a string or array is a common programming task in C#. The Array.IndexOf() method provides an efficient way to locate the position of a specific element within an array of strings. Syntax Following is the syntax for using Array.IndexOf() method − int index = Array.IndexOf(array, searchValue); Parameters array − The one-dimensional array to search searchValue − The object to locate in the array Return Value The method returns the index of the first occurrence of the specified value. If the value is ... Read More

C# Program to invert the order of elements in a sequence

Samual Sam
Updated on 17-Mar-2026 07:04:35

265 Views

In C#, you can invert the order of elements in a sequence using several built-in methods. The most common approaches include using Queryable.Reverse() with LINQ, Array.Reverse(), and Enumerable.Reverse(). Each method has its specific use cases and performance characteristics. Syntax Following is the syntax for using Queryable.Reverse() method − IQueryable result = sequence.AsQueryable().Reverse(); Following is the syntax for using Array.Reverse() method − Array.Reverse(array); Following is the syntax for using Enumerable.Reverse() method − IEnumerable result = sequence.Reverse(); Using Queryable.Reverse() Method The Queryable.Reverse() method returns an IQueryable that ... Read More

Decimal.ToString() Method in C#

AmitDiwan
Updated on 17-Mar-2026 07:04:35

320 Views

The Decimal.ToString() method in C# is used to convert the numeric value of a decimal instance to its equivalent string representation. This method provides various overloads to format the decimal value according to specific requirements. Syntax Following is the basic syntax for Decimal.ToString() method − public override string ToString(); The method also has overloaded versions for custom formatting − public string ToString(string format); public string ToString(IFormatProvider provider); public string ToString(string format, IFormatProvider provider); Parameters format − A standard or custom numeric format string (optional). provider − An object ... Read More

What does Array.IsSynchronized property of array class do in C#?

Arjun Thakur
Updated on 17-Mar-2026 07:04:35

222 Views

The Array.IsSynchronized property in C# gets a boolean value indicating whether access to the Array is synchronized (thread-safe). This property is part of the ICollection interface implementation and helps determine if an array can be safely accessed by multiple threads simultaneously. For standard C# arrays, this property always returns false, meaning that arrays are not inherently thread-safe. When multiple threads need to access the same array, you must implement your own synchronization using the SyncRoot property or other synchronization mechanisms. Syntax Following is the syntax for the Array.IsSynchronized property − public bool IsSynchronized { get; ... Read More

How are values assigned to arrays in C#?

George John
Updated on 17-Mar-2026 07:04:35

196 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
Updated on 17-Mar-2026 07:04:35

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
Updated on 17-Mar-2026 07:04:35

398 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
Updated on 17-Mar-2026 07:04:35

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
Updated on 17-Mar-2026 07:04:35

122 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
Updated on 17-Mar-2026 07:04:35

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

Advertisements