The String.IsNormalized() method in C# is used to indicate whether this string is in a particular Unicode normalization form. Unicode normalization ensures that text with the same meaning has a consistent binary representation, which is important for string comparison and text processing. Syntax The syntax is as follows − public bool IsNormalized(); public bool IsNormalized(System.Text.NormalizationForm normalizationForm); Parameters normalizationForm − A System.Text.NormalizationForm enumeration value that specifies the Unicode normalization form to check against. The possible values are: FormC − Canonical Decomposition followed by Canonical Composition FormD − Canonical Decomposition FormKC − Compatibility ... Read More
The StringDictionary class in C# provides an indexer property that allows you to get or set values using a key-based approach. This indexer uses the syntax dictionary[key] to access or modify values at the specified key. Syntax Following is the syntax for getting or setting values using the indexer − // Getting a value string value = stringDictionary[key]; // Setting a value stringDictionary[key] = newValue; Parameters key − A string that represents the key to locate in the StringDictionary. value − The string value to associate with the specified key when ... Read More
A thread is defined as the execution path of a program. Each thread defines a unique flow of control. If your application involves complicated and time-consuming operations, then it is often helpful to set different execution paths or threads, with each thread performing a particular job. Threads are lightweight processes. One common example of use of thread is implementation of concurrent programming by modern operating systems. Use of threads saves wastage of CPU cycle and increase efficiency of an application. In C#, the System.Threading.Thread class is used for working with threads. It allows creating and accessing individual threads ... Read More
Reflection is the process of examining and describing the metadata of types, methods, and properties in a code at runtime. The System.Reflection namespace enables you to obtain data about loaded assemblies, the elements within them like classes, methods, and value types. The most commonly used classes in System.Reflection include Assembly, AssemblyName, ConstructorInfo, MethodInfo, ParameterInfo, EventInfo, PropertyInfo, and MemberInfo. Syntax Following is the syntax for getting type information using reflection − TypeInfo typeInfo = typeof(ClassName).GetTypeInfo(); IEnumerable properties = typeInfo.DeclaredProperties; IEnumerable methods = typeInfo.DeclaredMethods; Using Reflection to Display Properties and Methods Reflection allows you ... Read More
Delegates and interfaces are both powerful constructs in C# that allow for flexible and extensible code. While they serve different purposes, they can sometimes be used to achieve similar ends, leading to confusion about when to use one over the other. This article will elucidate the differences and similarities between delegates and interfaces, and provide guidelines for their use. Syntax Following is the syntax for declaring a delegate − public delegate returnType DelegateName(parameters); Following is the syntax for declaring an interface − public interface IInterfaceName { returnType MethodName(parameters); } ... Read More
Removing all even numbers from an array is a common programming task that involves filtering out numbers divisible by 2. In C#, we can accomplish this using various approaches such as iterative methods, LINQ, or recursion to create a new array containing only odd numbers. Problem Description We are given an array and need to remove all the even numbers from it. The resulting array should only contain odd numbers. An even number is any integer that is divisible by 2 (i.e., number % 2 == 0), while an odd number leaves a remainder of 1 when divided ... Read More
The TimeSpan.FromMilliseconds() method in C# is used to return a TimeSpan that represents a specified number of milliseconds. This static method is particularly useful when you need to create time intervals based on millisecond values, such as delays, timeouts, or performance measurements. Syntax Following is the syntax for the TimeSpan.FromMilliseconds() method − public static TimeSpan FromMilliseconds(double value); Parameters The method accepts one parameter − value − A double that represents the number of milliseconds. It can be positive, negative, or zero. Return Value The method returns a TimeSpan ... Read More
A CSV file is a comma-separated values file that stores data in a tabular format. Most business organizations use CSV files to store and exchange structured data because of their simplicity and wide compatibility. In C#, we can read CSV files using the StreamReader class along with File.OpenRead() method. The data can then be parsed and stored in arrays or collections for further processing. Syntax Following is the basic syntax for reading a CSV file − StreamReader reader = new StreamReader(File.OpenRead(filePath)); while (!reader.EndOfStream) { var line = reader.ReadLine(); ... Read More
In LINQ, a Left Outer Join includes all elements from the left collection and matching elements from the right collection. When there's no match in the right collection, the result still includes the left element with null values for the right side. This is different from an Inner Join, which only includes matching elements from both collections. Left Outer Join ensures that no records from the left collection are lost, even when they don't have corresponding matches in the right collection. Syntax The Left Outer Join pattern using LINQ extension methods follows this structure − ... Read More
In this problem, we are given a number N, and we need to calculate the sum of the squares of the first N natural numbers. The first N natural numbers are 1, 2, 3, ..., N, and we need to find 1² + 2² + 3² + ... + N². Problem Description Given a positive integer N, calculate the sum of squares of the first N natural numbers using different approaches in C#. Example 1 Input: N = 4 Output: 30 Explanation: The squares of the first 4 natural numbers are: 1², ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance