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
Server Side Programming Articles
Page 773 of 2109
What is late binding in C#?
Late binding in C# refers to the process where the decision of which method to call is made at runtime rather than compile time. This is also known as dynamic polymorphism, where the actual method implementation is determined by the object type at runtime, not by the reference type. Late binding is implemented using virtual methods in base classes and override methods in derived classes. When a virtual method is called through a base class reference, the runtime determines which derived class method to execute based on the actual object type. How Late Binding Works In late ...
Read MoreWhat does the interface IStructuralEquatable do in C#?
The IStructuralEquatable interface in C# defines methods to support the comparison of objects for structural equality. This means two objects are considered equal if they have the same structure and equal values, rather than being the same reference. This interface is particularly useful for collections like arrays, tuples, and other composite objects where you want to compare the actual content rather than object references. Syntax The interface defines two methods − public interface IStructuralEquatable { bool Equals(object other, IEqualityComparer comparer); int GetHashCode(IEqualityComparer comparer); } Methods ...
Read MoreTime Functions in C#
The DateTime structure in C# provides numerous methods and properties for working with dates and times. These time functions allow you to manipulate DateTime instances by adding or subtracting specific time intervals, extracting time components, and performing various time-related operations. Time functions in C# are essential for applications that need to handle scheduling, logging, time calculations, and date arithmetic operations. Common Time Functions The following table shows the most commonly used time manipulation methods in the DateTime class − Method Description AddDays(Double) Returns a new DateTime that adds the ...
Read MoreHow to display Absolute value of a number in C#?
To find the absolute value of a number in C#, use the Math.Abs method. The absolute value represents the distance of a number from zero on the number line, always returning a non-negative result. Syntax The Math.Abs method is overloaded to work with different numeric types − Math.Abs(int value) Math.Abs(long value) Math.Abs(float value) Math.Abs(double value) Math.Abs(decimal value) Parameters value − The number whose absolute value is to be computed. Return Value Returns the absolute value of the specified number. If the number is positive or zero, it ...
Read MoreTrigonometric Functions in C#
Trigonometric functions in C# are part of the Math class in the System namespace. These functions enable you to perform mathematical calculations involving angles, including basic trigonometric operations (Sin, Cos, Tan) and their inverse functions (Asin, Acos, Atan). All angle measurements in C# trigonometric functions are in radians, not degrees. To convert degrees to radians, multiply by π/180. Common Trigonometric Functions Function Description Return Type Math.Sin(double) Returns the sine of the specified angle double Math.Cos(double) Returns the cosine of the specified angle double Math.Tan(double) Returns the ...
Read MoreHow to capture file not found exception in C#?
The FileNotFoundException is thrown when you try to access a file that does not exist on the system. This commonly occurs when using classes like StreamReader, File.ReadAllText(), or other file I/O operations with an incorrect file path. Syntax Following is the syntax for handling FileNotFoundException using try-catch − try { // File operation that might throw FileNotFoundException } catch (FileNotFoundException ex) { // Handle the exception Console.WriteLine("File not found: " + ex.Message); } Using StreamReader with Exception Handling When using StreamReader to read a ...
Read MoreHow to capture out of memory exception in C#?
The System.OutOfMemoryException occurs when the CLR fails to allocate sufficient memory for an operation. This exception is inherited from the System.SystemException class and can be caught using try-catch blocks to handle memory allocation failures gracefully. Common scenarios that trigger this exception include attempting to create very large arrays, working with StringBuilder objects that exceed their capacity, or processing extremely large datasets. Syntax Following is the syntax for catching OutOfMemoryException − try { // Code that might throw OutOfMemoryException } catch (OutOfMemoryException ex) { // Handle the exception ...
Read MoreHow to capture index out of range exception in C#?
The IndexOutOfRangeException occurs when you try to access an array element with an index that is outside the bounds of the array. This is a common runtime exception in C# that can be captured using try-catch blocks. Understanding Array Bounds Arrays in C# are zero-indexed, meaning the first element is at index 0. If an array has 5 elements, the valid indices are 0, 1, 2, 3, and 4. Accessing index 5 or higher will throw an IndexOutOfRangeException. Array Index Bounds ...
Read MoreHow to control for loop using break and continue statements in C#?
The break and continue statements provide powerful control flow mechanisms within for loops in C#. The break statement terminates the loop entirely, while the continue statement skips the current iteration and moves to the next one. Syntax Following is the syntax for using break statement in a for loop − for (initialization; condition; increment) { if (someCondition) { break; // exits the loop completely } // other statements } Following is the syntax for using continue statement in a ...
Read MoreWhat does Array.IsSynchronized property of array class do in C#?
The Array.IsSynchronized property in C# gets a boolean value indicating whether access to the Array is synchronized (thread-safe). This property is part of the ICollection interface implementation and helps determine if an array can be safely accessed by multiple threads simultaneously. For standard C# arrays, this property always returns false, meaning that arrays are not inherently thread-safe. When multiple threads need to access the same array, you must implement your own synchronization using the SyncRoot property or other synchronization mechanisms. Syntax Following is the syntax for the Array.IsSynchronized property − public bool IsSynchronized { get; ...
Read More