Skip to main content

Posts

c# - How to check char array contains a char

Check char array contains a char The following asp.net c# example code demonstrate us how can we determine/check whether a char array containsa specified character pogrammatically at run time in an asp.net application. .Net framework's char array eachelement value represent a Unicode character. We can determine whether a specified character exists in a char array by usingContains() method. Enumerable.Contains() method allow us to determine whether a sequence contains a specified elementby using the default equality comparer. This method exists in System.Linq namespace. Contains() method need to pass two parameters named 'source' and 'value'. The 'source' parameter represent a sequence(array) in which to locate the 'value'. And the 'value' parameter represent the value to locate in the sequence. Contains() method return a Boolean value. It return 'true' if the specified element is found; o...

c# - How to check string contains a string in string array

Check string contains a string in string array The following asp.net c# example code demonstrate us how can we determine whether string array valuescontains a string programmatically at run time in an asp.net application. .Net framework's string arrayrepresent an array of string data type elements. In this example, we will search a string (substring) within string array values and display result that which elements containthe specified string. To do this, first we need to loop through the string array elements. Next, we check each element valueto determine the specified string is exists in current element value or not. If we found the search string in array currentelement value then we display it in web browser. String Class String.Contans() method returns a value indicating whether a specified substring occurs within this string.String array elements value data type is system.string. So, we can apply String.Contains() method to check w...

c# - How to make array contains case insensitive

Array contains case insensitive The following asp.net c# example code demonstrate us how can we determine whether an array contains an elementby ignoring case programmatically at run time in an asp.net application. .Net framework's Enumerable.Contains()method determine whether a sequence contains a specified element. Enumerable.Contains<TSource>(IEnumerable<TSource>, TSource, IEqualityComparer<TSource>) overloaded methodallow us to determine whether a sequence contains a specified element by using a specified IEqualityCompararer<T>. To call this overloaded method, fist we need to specify the source array to locate the searched element. Next, we need topass the searched element value as parameter of Contains() method to locate it within entire array. We also need to specify anequality comparer to compare values. In this example code, we uses StringComparer.InvariantCultureIgnoreCase, StringComparer.CurrentCultu...

c# - How to copy elements in one array to another array

Copy elements from one Array to another Array The Array class provides methods for creating, manipulating, searching, and sorting arrays. The Array class is not part of the System.Collections namespaces. However, it is still considered a collection because it is based on the IList interface. An element is a value in an Array. The length of an Array is the total number of elements it can contain. The Array has a fixed capacity. The following .net c# tutorial code demonstrates how we can copy elements from one Array to another Array. That means we will copy all the elements from one Array to another Array. In this .net c# example code, we will use the Array class CopyTo() method to copy the elements from one Array instance to another Array instance. In the beginning, we have to initialize a new empty Array instance with the same size and the same data type as the source Array. This is the Array instance where we will put the elements that we wi...

c# - How to convert a byte array to a string

Convert a byte Array to a String The Array class provides methods for creating, manipulating, searching, and sorting arrays. The Array class is not part of the System.Collections namespaces. However, it is still considered a collection because it is based on the IList interface. An element is a value in an Array. The length of an Array is the total number of elements it can contain. The Array has a fixed capacity. The following .net c# tutorial code demonstrates how we can convert a byte Array to a String. That means we will get a String instance from byte Array elements. In this .net c# example code, we will use the ASCIIEncoding class GetString() method and Encoding class GetString() method. The Encoding class represents the character encoding. Encoding is the process of transforming a set of Unicode characters into a sequence of bytes and decoding is the process of transforming a sequence of encoded bytes into a set of Unicode characters. ...

c# - How to convert a string to a byte array

Convert a String to a byte Array The Array class provides methods for creating, manipulating, searching, and sorting arrays. The Array class is not part of the System.Collections namespaces. However, it is still considered a collection because it is based on the IList interface. An element is a value in an Array. The length of an Array is the total number of elements it can contain. The Array has a fixed capacity. The following .net c# tutorial code demonstrates how we can convert a String to a byte Array. That means we will get a byte Array instance from a String object. In this .net c# example code, we will use ASCII encoding and the Encoding class GetBytes() method. The Encoding class represents the character encoding. Encoding is the process of transforming a set of Unicode characters into a sequence of bytes and decoding is the process of transforming a sequence of encoded bytes into a set of Unicode characters. The Encoding ASCII pro...

c# - How to convert a string array to a list

Convert a String Array to a List The Array class provides methods for creating, manipulating, searching, and sorting arrays. The Array class is not part of the System.Collections namespaces. However, it is still considered a collection because it is based on the IList interface. An element is a value in an Array. The length of an Array is the total number of elements it can contain. The Array has a fixed capacity. The following .net c# tutorial code demonstrates how we can convert a String Array to a List. That means we create a String data type List from String Array elements. But there is no direct method in the Array class to convert a String Array to a String data type List. In this .net c# example code, we will use the Enumerable class OfType() and ToList() methods to create a String type List from a String Array instance. In the beginning, we will call the Enumerable class OfType() method to filter the String type elements from the Strin...