Csharp Articles

Page 129 of 196

How to Convert Hex String to Hex Number in C#?

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

In C#, converting a hexadecimal string to its numeric value is a common operation. Hexadecimal strings represent numbers in base 16 using digits 0-9 and letters A-F. C# provides several methods to convert hex strings to different numeric types depending on your needs. Syntax Following is the syntax for converting hex strings using different methods − Convert.ToInt32(hexString, 16) Convert.ToSByte(hexString, 16) int.Parse(hexString, NumberStyles.HexNumber) Using Convert.ToInt32() Method The most commonly used method is Convert.ToInt32() which converts a hex string to a 32-bit signed integer − using System; public class Program { ...

Read More

C# program to check whether a given string is Heterogram or not

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

A Heterogram is a string that contains no duplicate letters. Each character in the string appears exactly once. For example, words like "mobile", "cry", and "laptop" are heterograms because no letter is repeated. Examples of Heterograms mobile - No repeated letters cry - All unique letters laptop - Each letter appears once Algorithm The algorithm uses an integer array to track which letters have been encountered. For each character in the string − Convert the character to an array index using str[i] - ...

Read More

How to check if two Strings are anagrams of each other using C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

An anagram is a word or phrase formed by rearranging the letters of another word or phrase, using all the original letters exactly once. For example, "silent" and "listen" are anagrams because they contain the same letters in different arrangements. In C#, there are several approaches to check if two strings are anagrams. The most common method is to sort the characters of both strings and compare them for equality. Using Array.Sort() Method The simplest approach is to convert both strings to character arrays, sort them, and then compare the sorted arrays − ...

Read More

C# program to find Union of two or more Dictionaries

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

The union of two or more dictionaries combines all unique keys from the dictionaries. In C#, you can find the union using HashSet and the UnionWith() method to merge dictionary keys, or use LINQ methods to combine both keys and values. Syntax Following is the syntax for finding union of dictionary keys using HashSet − HashSet unionKeys = new HashSet(dict1.Keys); unionKeys.UnionWith(dict2.Keys); Following is the syntax for merging dictionary values using LINQ − var unionDict = dict1.Union(dict2).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); Using HashSet for Key Union The most straightforward ...

Read More

C# program to find Union of two or more Lists

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 1K+ Views

The Union operation in C# combines multiple lists while removing duplicate elements. The Union() method from LINQ returns distinct elements from both collections, preserving the order of first occurrence. Syntax Following is the syntax for using the Union() method − var result = list1.Union(list2); For multiple lists, chain the Union operations − var result = list1.Union(list2).Union(list3); Using Union() Method with Two Lists The Union()

Read More

C# program to concat two or more Lists

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

In C#, you can concatenate multiple List objects using the Concat() method from LINQ. This method creates a new sequence that contains all elements from the original lists in order without modifying the original lists. Syntax Following is the syntax for concatenating lists using the Concat() method − var result = list1.Concat(list2); For multiple lists, you can chain the Concat() calls − var result = list1.Concat(list2).Concat(list3); Using Concat() to Merge Two Lists Example using System; using System.Collections.Generic; using System.Linq; public class Demo { ...

Read More

C# program to find common values from two or more Lists

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

Finding common values from two or more Lists in C# is a frequent requirement in programming. The Intersect() method from LINQ provides an efficient way to identify elements that exist in multiple collections. Syntax Following is the syntax for using Intersect() method − var result = list1.Intersect(list2); For multiple lists, chain the Intersect() method − var result = list1.Intersect(list2).Intersect(list3); Using Intersect() with Two Lists The Intersect() method returns elements that appear in both lists. It automatically removes duplicates and maintains the order from the first list − Example ...

Read More

Union Method in C#

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

The Union method in C# is a LINQ extension method that returns the unique elements from both collections. It combines two sequences and automatically removes duplicate values, ensuring each element appears only once in the result. Syntax Following is the syntax for the Union method − public static IEnumerable Union( this IEnumerable first, IEnumerable second ) Parameters first − The first sequence to merge. second − The second sequence to merge. Return Value Returns an IEnumerable containing ...

Read More

String slicing in C# to rotate a string

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

String slicing in C# allows you to rotate characters within a string by combining substrings. This technique uses the Substring() method to extract portions of a string and rearrange them to achieve the desired rotation effect. String rotation involves moving characters from one position to another within the string. For example, rotating the first two characters of "welcome" to the end results in "lcomewe". Syntax Following is the syntax for the Substring() method − string.Substring(startIndex, length) For string rotation, combine two substrings − string rotated = str.Substring(n) + str.Substring(0, n); ...

Read More

String Formatting in C# to add padding

seetha
seetha
Updated on 17-Mar-2026 1K+ Views

String formatting with padding in C# allows you to align text in columns by adding spaces to the left or right of strings. This is particularly useful for creating formatted tables, reports, or aligned output displays. Padding is controlled by format specifiers that define the width and alignment of each placeholder in the format string. Syntax The basic syntax for padding in format strings is − string.Format("{index, width}", value) Where − index − The parameter index (0, 1, 2, etc.) width − The total width of the field Positive width − ...

Read More
Showing 1281–1290 of 1,951 articles
« Prev 1 127 128 129 130 131 196 Next »
Advertisements