Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Server Side Programming Articles
Page 810 of 2109
Merge two arrays using C# AddRange() method
The AddRange() method in C# is used to add elements from a collection to the end of a List. This method is particularly useful for merging arrays by first converting them to a list, adding both arrays using AddRange(), and then converting the result back to an array. Syntax Following is the syntax for the AddRange() method − public void AddRange(IEnumerable collection) Parameters collection − The collection whose elements should be added to the end of the List. The collection itself cannot be null, but it can contain elements that are null. ...
Read MoreC# program to copy a range of bytes from one array to another
The Buffer.BlockCopy method in C# is used to copy a range of bytes from one array to another. This method provides a fast, low-level approach for copying data between arrays and is particularly useful when working with byte arrays or when you need to copy a specific range of elements. Syntax Following is the syntax for the Buffer.BlockCopy method − Buffer.BlockCopy(sourceArray, sourceOffset, destinationArray, destinationOffset, count); Parameters sourceArray − The source array from which to copy bytes sourceOffset − The zero-based byte offset into the source array destinationArray − The destination array to ...
Read MoreC# Program to convert integer array to string array
Converting an integer array to a string array is a common task in C# programming. The most efficient approach is using the Array.ConvertAll() method, which applies a conversion function to each element in the source array and returns a new array of the target type. Syntax Following is the syntax for Array.ConvertAll() method − string[] result = Array.ConvertAll(sourceArray, converter); Parameters sourceArray − The source integer array to convert converter − A lambda expression or method that converts each element Return Value Returns a new string ...
Read MoreC# program to check if a value is in an array
Use the Array.Exists method to check if a value is in an array or not. This method returns a boolean value indicating whether the specified element exists in the array. Syntax Following is the syntax for Array.Exists method − public static bool Exists(T[] array, Predicate match) Parameters array − The one-dimensional array to search. match − A predicate that defines the conditions of the element to search for. Return Value Returns true if the array contains an element that matches the conditions defined by the ...
Read MoreClear a list in C#
To clear a list in C#, you use the Clear() method which removes all elements from the list. This method is part of the List class and provides an efficient way to empty a list without recreating it. Syntax Following is the syntax for the Clear()
Read MoreC# program to create a List with elements from an array
In C#, you can easily create a List with elements from an existing array. The List constructor accepts an IEnumerable parameter, which allows you to initialize the list directly with array elements. Syntax Following is the syntax to create a list from an array − List listName = new List(arrayName); You can also use the ToList() extension method − List listName = arrayName.ToList(); Using List Constructor The most straightforward way is to pass the array directly to the List constructor − using System; using System.Collections.Generic; public ...
Read MoreC# program to find the index of an element in a List
In C#, you can find the index of an element in a List using the IndexOf() method. This method returns the zero-based index of the first occurrence of the specified element, or -1 if the element is not found. Syntax Following is the syntax for the IndexOf() method − int IndexOf(T item) int IndexOf(T item, int startIndex) int IndexOf(T item, int startIndex, int count) Parameters item: The element to locate in the list. startIndex: The zero-based starting index of the search (optional). count: The number of elements to search (optional). ...
Read MoreC# Program to find the smallest element from an array using Lambda Expressions
Lambda expressions in C# provide a concise way to write anonymous functions. When combined with LINQ methods like Min(), they offer powerful tools for array operations. This article demonstrates how to find the smallest element from an array using lambda expressions. Syntax The basic syntax for using Min() with lambda expressions − array.Min() // finds minimum value directly array.Min(element => expression) // finds minimum based on expression Using Min() Without Lambda Expression For ...
Read MoreC# program to get the List of keys from a Dictionary
In C#, you can extract all the keys from a Dictionary as a List using the Keys property. This is useful when you need to work with dictionary keys as a separate collection or perform operations like sorting, filtering, or iteration. Syntax Following is the syntax to get keys from a Dictionary − Dictionary dictionary = new Dictionary(); List keys = new List(dictionary.Keys); You can also use LINQ to convert keys to a List − List keys = dictionary.Keys.ToList(); Using Dictionary.Keys Property The Keys property returns a collection of ...
Read MoreInsert more than one element at once in a C# List
The InsertRange() method in C# allows you to insert multiple elements into a List at a specified position. This method is useful when you need to add a collection of elements at once rather than adding them one by one. Syntax Following is the syntax for the InsertRange() method − public void InsertRange(int index, IEnumerable collection) Parameters index − The zero-based index at which the new elements should be inserted. collection − The collection whose elements should be inserted into the List. The collection itself cannot be null, but ...
Read More