George John

George John

789 Articles Published

Articles by George John

789 articles

What is an object pool in C#?

George John
George John
Updated on 17-Mar-2026 1K+ Views

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 More

How to calculate Power of a number using recursion in C#?

George John
George John
Updated on 17-Mar-2026 1K+ Views

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 More

File Permissions in C#

George John
George John
Updated on 17-Mar-2026 3K+ Views

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 More

The "E" and "e" custom specifiers in C#

George John
George John
Updated on 17-Mar-2026 470 Views

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 More

What is the equivalent of a VB module in C#?

George John
George John
Updated on 17-Mar-2026 1K+ Views

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 More

Check if both halves of the string have same set of characters in C#

George John
George John
Updated on 17-Mar-2026 244 Views

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 More

C# DateTime to add days to the current date

George John
George John
Updated on 17-Mar-2026 7K+ Views

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 More

What is boxing in C#?

George John
George John
Updated on 17-Mar-2026 575 Views

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 More

C# Fixed-Point ("F") Format Specifier

George John
George John
Updated on 17-Mar-2026 1K+ Views

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 More

C# program to remove all duplicates words from a given sentence

George John
George John
Updated on 17-Mar-2026 1K+ Views

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
Showing 1–10 of 789 articles
« Prev 1 2 3 4 5 79 Next »
Advertisements