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
DateTime.DaysInMonth() Method in C#
The DateTime.DaysInMonth() method in C# returns the number of days in the specified month and year. This static method is particularly useful for calendar calculations and date validations, automatically handling leap years and different month lengths. Syntax Following is the syntax for the DateTime.DaysInMonth() method − public static int DaysInMonth(int year, int month); Parameters year − An integer representing the year (1 to 9999). month − An integer representing the month (1 to 12). Return Value Returns an int representing the number of days in ...
Read MoreC# program to count total set bits in a number
A set bit refers to a bit that has a value of 1 in the binary representation of a number. Counting set bits is a common programming problem that involves examining each bit position to determine how many are set to 1. For example, the number 11 in decimal has the binary representation 1011, which contains 3 set bits (three 1s). Approach The most straightforward approach uses bitwise operations to examine each bit − Use the bitwise AND operator (&) with 1 to check if the least significant bit is set Right-shift ...
Read MoreWhat are the differences between ref and out parameters in C#?
The ref and out parameters in C# are both used to pass arguments by reference, but they have distinct behaviors and use cases. Both allow methods to modify the original variable, but they differ in initialization requirements and intended purposes. Syntax Following is the syntax for declaring ref parameters − public void MethodName(ref int parameter) { // parameter can be read and modified } Following is the syntax for declaring out parameters − public void MethodName(out int parameter) { // parameter must be assigned ...
Read MoreWhat is the difference between Read(), ReadKey() and ReadLine() methods in C#?
The Console class in C# provides three different methods for reading user input: Read(), ReadKey(), and ReadLine(). Each method serves a specific purpose and returns different types of data from the standard input stream. Syntax Following are the syntaxes for the three input methods − int result = Console.Read(); // Returns ASCII value ConsoleKeyInfo keyInfo = Console.ReadKey(); // Returns key information string input = Console.ReadLine(); // Returns string Console.Read() Method The Read() method reads the next character from the ...
Read MoreHow to instantiate a class in C#?
In C#, you create an instance of a class using the new operator. This process is called instantiation, which allocates memory for the object and calls the class constructor. Syntax Following is the basic syntax for instantiating a class − ClassName objectName = new ClassName(); For classes with parameterized constructors − ClassName objectName = new ClassName(parameters); Using Default Constructor When you instantiate a class without parameters, it calls the default constructor. Here's an example using a Line class − using System; class Line { ...
Read MoreGroup by Operator in C#
The Group By operator in C# is used to group elements in a collection based on a specified key. It separates the results into groups where each group contains elements that share the same key value. Syntax Following is the syntax for using Group By with LINQ query syntax − var result = from element in collection group element by keySelector; Following is the syntax for using Group By with method syntax − var result = collection.GroupBy(keySelector); ...
Read MoreC# Cast method
The Cast() method in C# is a LINQ extension method used to cast each element in a collection from one type to another. It is particularly useful when working with collections of object type that need to be converted to a specific type for further processing. Syntax Following is the syntax for the Cast() method − public static IEnumerable Cast(this IEnumerable source) Parameters source − The collection containing elements to be cast. TResult − The target type to cast elements to. Return Value Returns an IEnumerable containing each element ...
Read MoreExtracting MAC address using C#
A MAC address (Media Access Control address) is a unique identifier assigned to network interfaces for communications at the data link layer of a network segment. It serves as a network address for most IEEE 802 network technologies, including Ethernet, Wi-Fi, and Bluetooth. In C#, you can extract MAC addresses using the NetworkInterface class from the System.Net.NetworkInformation namespace. This class provides methods to enumerate all network interfaces on the local computer and retrieve their physical addresses. Syntax Following is the syntax for getting all network interfaces − NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); Following is ...
Read MoreConvert.ToBoolean(String, IFormatProvider) Method in C#
The Convert.ToBoolean(String, IFormatProvider) method in C# converts a string representation to an equivalent Boolean value using culture-specific formatting information. This method accepts only specific string values: "True", "False", or their equivalents in different cultures. Syntax Following is the syntax − public static bool ToBoolean(string value, IFormatProvider provider); Parameters value − A string containing the value of either TrueString or FalseString. provider − An object that supplies culture-specific formatting information (this parameter is ignored for Boolean conversions). Return Value Returns true if value equals TrueString, or false if value equals ...
Read MoreWhat are the differences between class methods and class members in C#?
In C#, understanding the difference between class members and class methods is fundamental to object-oriented programming. Class members are the data components that store the state of an object, while class methods are the functions that operate on that data and define the object's behavior. Class Members vs Class Methods Class Members Class Methods Store data and represent the state of an object Define behavior and operations on the object's data Examples: fields, properties, constants Examples: functions, procedures, constructors Hold values that can change over time Execute ...
Read More