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
What is the difference between function overriding and method hiding in C#?
In C#, function overriding and method hiding are two different mechanisms for changing method behavior in derived classes. While both allow a child class to provide its own implementation of a parent class method, they work in fundamentally different ways. Function Overriding Function overriding allows a subclass to provide a specific implementation of a method that is already defined in its parent class. The parent method must be marked as virtual, abstract, or override, and the child method uses the override keyword. Syntax // Parent class public virtual ReturnType MethodName() { } // Child ...
Read MoreHow to find date difference in C#?
To find the difference between two dates in C#, you can use the DateTime class along with the TimeSpan structure. The DateTime subtraction operation returns a TimeSpan object that represents the time difference between two dates. Syntax Following is the syntax for calculating date difference − DateTime date1 = new DateTime(year, month, day); DateTime date2 = new DateTime(year, month, day); TimeSpan difference = date2 - date1; The TimeSpan object provides various properties to access different units of the difference − difference.Days // Total ...
Read MoreC# program to find Union of two or more Lists
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 MoreRepresent Int64 as a Binary string in C#
To represent Int64 as a binary string in C#, use the Convert.ToString() method with base 2 as the second parameter. Int64 represents a 64-bit signed integer that can hold values from -9, 223, 372, 036, 854, 775, 808 to 9, 223, 372, 036, 854, 775, 807. Syntax Following is the syntax for converting Int64 to binary string − Convert.ToString(longValue, 2) Parameters longValue − The Int64 value to convert 2 − The base for binary representation Return Value Returns a string representation of the Int64 value in binary format (base ...
Read MoreMath.Max() Method in C#
The Math.Max() method in C# returns the larger of two specified numbers. This static method is overloaded to work with various numeric types including int, double, decimal, float, and more. Syntax The Math.Max() method has multiple overloads for different numeric types − public static int Max(int val1, int val2); public static double Max(double val1, double val2); public static decimal Max(decimal val1, decimal val2); public static float Max(float val1, float val2); public static long Max(long val1, long val2); public static byte Max(byte val1, byte val2); public static short Max(short val1, short val2); public static uint Max(uint val1, ...
Read MoreHow to capture null reference exception in C#?
A NullReferenceException occurs when you attempt to access a member (method, property, or field) of a null object reference. This is one of the most common runtime exceptions in C#. What Causes NullReferenceException? The exception is thrown when you try to access members of an object that has not been initialized or has been set to null − string str = null; int length = str.Length; // Throws NullReferenceException Using Null Checks The most straightforward way to prevent NullReferenceException is to check for null before accessing object members − using System; ...
Read MoreHow to count the number of items in a C# list?
The Count property in C# is used to determine the number of elements in a List. This property returns an integer representing the total count of items currently stored in the list. Syntax Following is the syntax for using the Count property − int count = myList.Count; Parameters The Count property does not take any parameters. It is a read-only property that returns the current number of elements in the list. Return Value The Count property returns an int value representing the number of elements in the list. It returns 0 ...
Read MoreHow to print a blank line in C#?
To print a blank line in C#, you can use several methods. The most common approach is using Console.WriteLine() without any parameters, which outputs an empty line to the console. Syntax Following are the different ways to print a blank line − Console.WriteLine(); // Empty line Console.WriteLine(""); // Empty string Console.WriteLine(" "); // Single space Console.Write(""); // Newline character ...
Read MoreC# program to concat two or more Lists
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 MoreC# All method
The All() method in C# is a LINQ extension method that checks whether all elements in a collection satisfy a given condition. It returns a bool value − true if all elements meet the condition, or false if even one element fails the condition. The method is available for any IEnumerable collection and is commonly used with arrays, lists, and other collections for validation and filtering operations. Syntax Following is the syntax for the All() method − bool result = collection.All(predicate); Parameters predicate − A lambda expression or delegate that ...
Read More