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 by Arjun Thakur
Page 11 of 75
Environment.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 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 MoreHow to iterate over a C# list?
A List in C# is a generic collection that stores elements of the same type. There are several ways to iterate over a C# list, each with its own advantages depending on your specific needs. Syntax Following is the basic syntax for declaring and initializing a list − List listName = new List(); Following are the common iteration syntaxes − // foreach loop foreach(var item in list) { // process item } // for loop for(int i = 0; i < list.Count; i++) { // ...
Read MoreWhat is aggregation in C#?
Aggregation in C# represents a has-a relationship between objects where one class contains or uses another class. In aggregation, the contained object can exist independently of the container object, making it a weak association. For example, an Employee has an Address, and a Department has multiple Employees. The key characteristic of aggregation is that when the container object is destroyed, the contained objects continue to exist independently. Syntax Following is the syntax for implementing aggregation in C# − public class ContainerClass { private ContainedClass containedObject; ...
Read MoreConvert.ToByte Method in C#
The Convert.ToByte method in C# converts a specified value to an 8-bit unsigned integer (byte). A byte can hold values from 0 to 255, making it useful for representing small integers, ASCII characters, and binary data. This method provides a safe way to convert various data types to byte values, with built-in overflow checking that throws an OverflowException if the value is outside the valid byte range. Syntax Following are the common overloads of the Convert.ToByte method − Convert.ToByte(object value) Convert.ToByte(string value) Convert.ToByte(char value) Convert.ToByte(int value) Convert.ToByte(double value) Parameters value − ...
Read MoreClass and Static Variables in C#
In C#, static variables belong to the class itself rather than to any specific instance of the class. They are shared among all instances of the class and can be accessed using the class name without creating an object. Class variables (instance variables) belong to individual objects and each instance has its own copy of these variables. Static Variables Static variables are declared using the static keyword and are useful for defining constants or shared data across all instances of a class. Syntax public static dataType variableName; Static vs ...
Read MoreInitialization vs Instantiation in C#
In C#, initialization and instantiation are two fundamental concepts that are often confused. Initialization refers to assigning a value to a variable when it is declared, while instantiation refers to creating a new object instance using the new keyword. Initialization Initialization is the process of assigning a value to a variable at the time of declaration. This can be done for value types, reference types, and collections − Value Type Initialization using System; class Program { public static void Main() { int val = 50; ...
Read MoreC# Program to return specified number of elements from the beginning of a sequence
The Take() method in C# is a LINQ extension method that returns a specified number of elements from the beginning of a sequence. This method is particularly useful when you need to retrieve only the first few elements from a collection, especially after sorting or filtering operations. Syntax Following is the syntax for the Take() method − public static IEnumerable Take( this IEnumerable source, int count ) Parameters source − The sequence to return elements from. count − The number of elements to return ...
Read MoreFibonacci Series in C#
The Fibonacci series is a sequence of numbers where each number is the sum of the two preceding numbers. The series typically starts with 0 and 1, producing the sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. In C#, there are multiple ways to generate the Fibonacci series, including iterative and recursive approaches. Fibonacci Series Pattern 0 1 1 2 3 ...
Read More