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 George John
789 articles
What is an object pool in C#?
An object pool in C# is a software design pattern that maintains a collection of reusable objects to optimize resource usage and improve performance. Instead of constantly creating and destroying expensive objects, the pool keeps pre-initialized objects ready for use. The object pool pattern works on two fundamental operations − Rent/Get: When an object is needed, it is retrieved from the pool. Return: When the object is no longer needed, it is returned to the pool for reuse. Object Pool Pattern ...
Read MoreHow to calculate Power of a number using recursion in C#?
To calculate power of a number using recursion in C#, we use the mathematical principle that n^p = n × n^(p-1). The recursive function calls itself with a reduced power until it reaches the base case. Syntax Following is the syntax for a recursive power function − static long Power(int number, int power) { if (power == 0) { return 1; // base case } return number * Power(number, power - 1); // recursive ...
Read MoreFile Permissions in C#
File permissions in C# are managed using the FileIOPermission class from the System.Security.Permissions namespace. This class controls the ability to access files and folders by defining what operations are allowed on specific file system resources. The FileIOPermission class is part of .NET's Code Access Security (CAS) system and helps ensure that applications only perform file operations they are explicitly granted permission to execute. Syntax Following is the syntax for creating a FileIOPermission instance − FileIOPermission permission = new FileIOPermission(PermissionState.None); permission.AllLocalFiles = FileIOPermissionAccess.Read; Following is the syntax for adding specific path permissions − ...
Read MoreThe "E" and "e" custom specifiers in C#
The "E" and "e" custom specifiers in C# are used to format numbers in scientific notation (exponential notation). When any of these specifiers appear in a format string followed by at least one zero, the number is formatted with an "E" or "e" separator between the mantissa and the exponent. Syntax The following format specifiers create exponential notation − "E0" // Uppercase E with minimum exponent digits "e0" // Lowercase e with minimum exponent digits "E+0" // Uppercase E with explicit + sign "e+0" // Lowercase ...
Read MoreWhat is the equivalent of a VB module in C#?
In VB.NET, a module is used to store loose code and variables that are accessible from anywhere in the application without needing to instantiate an object. Variables in a module maintain their state throughout the application lifetime. The C# equivalent of a VB.NET module is a static class. Static classes provide the same functionality − global accessibility without instantiation and persistent state through static members. Syntax Following is the syntax for creating a static class in C# − public static class ClassName { public static void MethodName() { ...
Read MoreCheck if both halves of the string have same set of characters in C#
To check if both halves of a string have the same set of characters in C#, we need to split the string into two equal halves and compare the character frequencies in each half. This problem is useful for validating palindromic properties and string pattern matching. Algorithm The approach uses character frequency counting − Create two frequency arrays to count characters in each half Iterate from both ends of the string toward the center Count character occurrences in the left half and right half Compare the frequency arrays to determine if both halves contain the same ...
Read MoreC# DateTime to add days to the current date
The DateTime class in C# provides the AddDays() method to add a specified number of days to a date. This method is commonly used to calculate future dates from the current date or any given date. Syntax Following is the syntax for using AddDays() method − DateTime newDate = dateTime.AddDays(numberOfDays); Parameters The AddDays() method accepts the following parameter − numberOfDays − A double value representing the number of days to add. This can be positive (future dates) or negative (past dates). Return Value The method returns a new ...
Read MoreWhat is boxing in C#?
Boxing in C# is the process of converting a value type to an object type. When boxing occurs, the value stored on the stack is copied to an object stored on the heap memory. This is an implicit conversion that allows value types to be treated as reference types. Syntax Boxing happens implicitly when a value type is assigned to an object variable − int valueType = 50; object boxedValue = valueType; // implicit boxing Unboxing requires explicit casting to convert back to the original value type − object boxedValue = 50; ...
Read MoreC# Fixed-Point ("F") Format Specifier
The Fixed-Point ("F") format specifier in C# converts a number to a string with a fixed number of decimal places. It produces output in the form "-ddd.ddd..." where "d" represents a digit (0-9). The negative sign appears only for negative numbers. Syntax Following is the syntax for using the Fixed-Point format specifier − number.ToString("F") // Default 2 decimal places number.ToString("Fn") // n decimal places (0-99) number.ToString("F", culture) // With specific culture Default Precision When no precision ...
Read MoreC# program to remove all duplicates words from a given sentence
Removing duplicate words from a sentence is a common string manipulation task in C#. This process involves splitting the sentence into individual words, identifying duplicates, and keeping only unique words while preserving the original structure. There are several approaches to accomplish this task, ranging from using LINQ's Distinct() method to using collections like HashSet for efficient duplicate removal. Using LINQ Distinct() Method The Distinct() method from LINQ provides a straightforward way to remove duplicates from a collection − using System; using System.Linq; public class Program { public static void Main() { ...
Read More