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
Articles on Trending Technologies
Technical articles with clear explanations and examples
C# program to Reverse words in a string
In C#, reversing words in a string means reversing each individual word while keeping the words in their original positions. For example, "Hello World" becomes "olleH dlroW" where each word is reversed but the word order remains the same. Syntax Using LINQ with Split(), Select(), and Reverse() methods − string result = string.Join(" ", str.Split(' ').Select(word => new string(word.Reverse().ToArray()))); Using a traditional loop approach − string[] words = str.Split(' '); for (int i = 0; i < words.Length; i++) { words[i] = ReverseWord(words[i]); } string result = string.Join(" ...
Read MoreWhat are the difference between Composition and Aggregation in C#?
Composition and Aggregation are two important types of associations in C# that represent different levels of dependency between classes. Understanding these relationships helps design better object-oriented systems with proper coupling and lifecycle management. Composition Composition represents a strong "part-of" relationship where the child object cannot exist independently of the parent object. When the parent is destroyed, all child objects are also destroyed automatically. Composition: Strong Ownership Car (Owner) Engine (Owned) ...
Read MoreHow to join two lists in C#?
To join two lists in C#, you can use several methods. The most common approaches are using the AddRange() method to modify an existing list, or using LINQ's Concat() method to create a new combined list without modifying the originals. Syntax Using AddRange() to modify the first list − list1.AddRange(list2); Using LINQ Concat() to create a new list − var combinedList = list1.Concat(list2).ToList(); Using AddRange() Method The AddRange() method adds all elements from the second list to the end of the first list, modifying the original list − ...
Read MoreC# program to get the file name in C#
In C#, you can extract the file name from a full path using the Path.GetFileName() method from the System.IO namespace. This method returns only the file name and extension, without the directory path. Syntax Following is the syntax for using Path.GetFileName() method − string fileName = Path.GetFileName(filePath); Parameters filePath − A string containing the full path to the file. Return Value The method returns a string containing the file name and extension. If the path ends with a directory separator, it returns an empty string. Using ...
Read MoreC# Linq ElementAt Method
The ElementAt() method in C# LINQ returns the element at a specified index position in a sequence. It is part of the LINQ extension methods and can be used with any IEnumerable collection. The ElementAt() method throws an ArgumentOutOfRangeException if the index is out of bounds. For safer access, you can use ElementAtOrDefault(), which returns the default value for the type if the index is invalid. Syntax Following is the syntax for the ElementAt() method − public static TSource ElementAt(this IEnumerable source, int index) Following is the syntax for the ElementAtOrDefault() method − ...
Read MoreC# program to find IP Address of the client
To find the IP address of the client machine in C#, we use the DNS (Domain Name System) class from the System.Net namespace. This involves getting the hostname first and then resolving it to obtain the associated IP addresses. Syntax Following is the syntax to get the hostname − string hostName = Dns.GetHostName(); Following is the syntax to get IP addresses from hostname − IPHostEntry hostEntry = Dns.GetHostEntry(hostName); IPAddress[] addresses = hostEntry.AddressList; How It Works The process involves two main steps: Dns.GetHostName() retrieves the hostname of the ...
Read MoreEnvironment.NewLine in C#
The Environment.NewLine property in C# provides a platform-independent way to add line breaks in strings. It automatically returns the appropriate newline character sequence for the current operating system − \r on Windows and on Unix-based systems. Using Environment.NewLine ensures your code works correctly across different platforms without hardcoding specific line break characters. Syntax Following is the syntax for using Environment.NewLine − string result = text1 + Environment.NewLine + text2; You can also use it in string concatenation or interpolation − string result = $"Line 1{Environment.NewLine}Line 2"; Basic Usage ...
Read MoreSortable ("s") Format Specifier in C#
The Sortable ("s") format specifier in C# represents a standardized date and time format that produces ISO 8601-compliant strings. This format is particularly useful for sorting dates chronologically as strings and for data interchange between different systems. The "s" format specifier is defined by the DateTimeFormatInfo.SortableDateTimePattern property and follows a consistent pattern regardless of the current culture settings. Syntax The sortable format specifier uses the following syntax − DateTime.ToString("s") This corresponds to the custom format pattern − yyyy'-'MM'-'dd'T'HH':'mm':'ss Format Pattern Breakdown Sortable Format Pattern: ...
Read MoreDecimal.Divide() Method in C#
The Decimal.Divide() method in C# is used to divide two specified Decimal values and return the quotient. This static method provides precise division operations for financial and monetary calculations where accuracy is critical. Syntax Following is the syntax − public static decimal Divide(decimal val1, decimal val2); Parameters val1 − The dividend (the number to be divided). val2 − The divisor (the number by which val1 is divided). Return Value Returns a decimal value representing the result of dividing val1 by val2. The method throws a ...
Read MoreWhat is early binding in C#?
Early binding in C# is the mechanism of linking a method call with its implementation during compile time. It is also called static binding because the method to be called is determined at compilation rather than at runtime. In early binding, the compiler knows exactly which method will be executed based on the method signature (name, parameters, and their types). This results in faster execution since no runtime resolution is needed. How Early Binding Works C# achieves early binding through static polymorphism, which includes method overloading and operator overloading. The compiler resolves which specific method to call ...
Read More