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
Page 6 of 79
What are generic delegates in C#?
Generic delegates in C# allow you to create delegate types with type parameters, providing flexibility to work with different data types without defining separate delegate declarations for each type. The .NET Framework provides several built-in generic delegates in the System namespace that eliminate the need for custom delegate definitions in most scenarios. Syntax Following is the syntax for declaring a custom generic delegate − delegate TResult DelegateName(T parameter); Built-in generic delegates use these syntaxes − Action actionDelegate = method; // void return type Func funcDelegate = method; // ...
Read MoreC# program to perform Quick sort using Recursion
Quick Sort is a highly efficient sorting algorithm that uses the divide and conquer approach. It selects a pivot element from the array and partitions the other elements into two sub-arrays according to whether they are less than or greater than the pivot. The sub-arrays are then recursively sorted. The algorithm works by placing the pivot in its correct position and then recursively applying the same process to the left and right sub-arrays until the entire array is sorted. How Quick Sort Works Quick Sort Process Initial Array: ...
Read MoreWhat are dynamic data types in C#?
The dynamic data type in C# allows you to store any type of value in a variable. Unlike other data types, type checking for dynamic variables occurs at runtime rather than compile-time, providing flexibility but requiring careful handling to avoid runtime errors. Syntax Following is the syntax for declaring a dynamic variable − dynamic = value; Basic Dynamic Variable Declaration Example using System; class Program { public static void Main() { dynamic val1 = 100; ...
Read MoreWhat are abstract properties in C#?
An abstract property in C# is a property declared in an abstract class without implementation. The derived classes must provide the actual implementation of the property accessor (get, set, or both). Abstract properties enforce a contract that ensures all derived classes implement the required property. Abstract properties are useful when you want to define a common structure across related classes but need each class to calculate or store the property value differently. Syntax Following is the syntax for declaring an abstract property − public abstract class ClassName { public abstract DataType PropertyName ...
Read MoreHow to find the file using C#?
Use the Directory.GetFiles and Directory.GetDirectories methods in C# to search for files in a directory structure. These methods provide powerful options to recursively search through subdirectories and apply search patterns. Syntax Following is the syntax for finding files using Directory.GetFiles − string[] files = Directory.GetFiles(path, searchPattern, SearchOption.AllDirectories); Following is the syntax for finding directories using Directory.GetDirectories − string[] directories = Directory.GetDirectories(path, searchPattern, SearchOption.AllDirectories); Parameters path − The directory path to search in searchPattern − The search string to match file/folder names (supports wildcards like * and ?) SearchOption ...
Read MoreShell Sort program in C#
Shell Sort is an optimized version of insertion sort that allows the exchange of items that are far apart in the array. It starts with a large gap between compared elements and progressively reduces this gap until it becomes 1. This algorithm was developed by Donald Shell in 1959, hence the name. Unlike insertion sort which compares adjacent elements, Shell Sort compares elements separated by a gap. This reduces the number of shifts needed and makes the algorithm more efficient for larger datasets. How Shell Sort Works Shell Sort works by dividing the array into smaller sub-arrays ...
Read MoreDeadlock and Starvation in C#
Deadlock occurs when two or more threads are permanently blocked, each waiting for a resource held by another thread. This creates a circular dependency where no thread can proceed, making it a critical problem in multithreaded applications. Starvation happens when a thread is indefinitely denied access to resources it needs, typically because other threads with higher priority continuously monopolize those resources. Understanding Deadlock A deadlock situation arises when threads hold locks and wait for other locks in a circular chain. The classic scenario involves two threads and two resources − Thread One Thread ...
Read MoreClear a Linked List in C#
The Clear() method in C# is used to remove all nodes from a LinkedList. This method provides an efficient way to empty the entire linked list in a single operation, resetting the Count property to zero. Syntax Following is the syntax for the Clear() − linkedList.Clear(); Parameters The Clear() method takes no parameters. Return Value The Clear() method does not return any value. It is a void method that modifies the linked list in-place. LinkedList Clear() Operation Before Clear(): ...
Read MoreWay to read input from console in C#
The Console.ReadLine() method is the primary way to read input from the console in C#. This method reads a complete line of text from the console and returns it as a string. Since all console input is received as text, you need to convert it to the appropriate data type when working with numbers or other non-string values. Syntax Following is the syntax for reading console input − string input = Console.ReadLine(); For converting string input to other data types − int number = Convert.ToInt32(input); ...
Read MoreC# program to display the previous day
To display the previous day in C#, use the AddDays() method with a value of -1. This method allows you to add or subtract days from a DateTime object. Syntax Following is the syntax for getting the current date − DateTime.Today Following is the syntax for getting the previous day using AddDays() − DateTime.Today.AddDays(-1) Using DateTime.Today.AddDays(-1) The DateTime.Today property returns the current date with the time set to midnight. The AddDays(-1) method subtracts one day from this date − using System; public class Demo { ...
Read More