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 5 of 79
What 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 MoreHow to convert a string into int in C#?
Converting a string to an integer in C# is a common task that can be accomplished using several methods. The most straightforward approach is using Int32.Parse() method, which converts the string representation of a number to its 32-bit signed integer equivalent. Syntax Following is the syntax for using Int32.Parse() method − int result = Int32.Parse(stringValue); Following is the syntax for using Convert.ToInt32() method − int result = Convert.ToInt32(stringValue); Following is the syntax for using int.TryParse() method − bool success = int.TryParse(stringValue, out int result); Using Int32.Parse() ...
Read MoreNetworking in C#
The .NET Framework provides a layered, extensible, and managed implementation of networking services that you can easily integrate into your applications. The System.Net namespace contains classes for network communication, web requests, DNS operations, and secure connections. Syntax To use networking classes, include the System.Net namespace − using System.Net; Creating a URI and web request − Uri uri = new Uri("http://www.example.com/"); WebRequest request = WebRequest.Create(uri); Using Uri Class The Uri class in C# provides object representation of a uniform resource identifier (URI). It helps parse and manipulate web addresses − ...
Read More