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
C# equivalent to Java's Thread.setDaemon?
C# equivalent to Java's Thread.setDaemon is the concept of foreground and background threads. In C#, background threads serve the same purpose as daemon threads in Java − they run in the background and are automatically terminated when all foreground threads complete. When all foreground threads terminate, the CLR (Common Language Runtime) automatically shuts down the application, causing all background threads to be terminated immediately. Foreground threads keep the application alive until they complete execution. Syntax Following is the syntax to create a background thread using the IsBackground property − Thread thread = new Thread(methodName); thread.IsBackground ...
Read MoreIS vs AS Operators in C#
The is and as operators in C# are used for type checking and type conversion. The is operator checks if an object is compatible with a given type and returns a boolean value, while the as operator attempts to convert an object to a specified type and returns null if the conversion fails. Syntax Following is the syntax for the is operator − expr is type Following is the syntax for the as operator − expr as type Where expr is the expression to test and type is the target ...
Read MoreLambda Expressions in C#
A lambda expression in C# is an anonymous function that provides a concise way to write inline functions. Lambda expressions use the => operator, read as "goes to", which separates the input parameters from the expression body. Lambda expressions are commonly used with LINQ methods, event handlers, and delegates to create short, readable code without defining separate methods. Syntax Following is the basic syntax for lambda expressions − (input-parameters) => expression For single parameter, parentheses are optional − x => x * 2 For multiple statements, use curly braces ...
Read MoreC# Equivalent to Java Functional Interfaces
The C# equivalent to Java's functional interfaces is delegates. Delegates in C# provide the same functionality as functional interfaces in Java, allowing you to treat methods as first-class objects and use lambda expressions for concise code. Java functional interfaces define a contract with a single abstract method, while C# delegates directly represent method signatures that can be assigned lambda expressions or method references. Syntax Following is the syntax for declaring a delegate in C# − public delegate ReturnType DelegateName(ParameterType parameter); Following is the syntax for assigning a lambda expression to a delegate − ...
Read MoreC# Program to remove whitespaces in a string
In C#, there are several ways to remove whitespaces from a string. You can remove all spaces, only leading and trailing spaces, or all types of whitespace characters including tabs and newlines. Using String.Replace() Method The Replace()
Read MoreDefault constructor in C#
A default constructor in C# is a constructor that takes no parameters. When you create an object of a class, the constructor is automatically invoked. The constructor has the same name as the class and is used to initialize the object. If you don't explicitly define any constructor in your class, C# automatically provides a default constructor. However, if you define any parameterized constructor, you must explicitly define the default constructor if you want to use it. Syntax Following is the syntax for declaring a default constructor − public class ClassName { ...
Read MoreMajor features of C# programming
C# is a modern, general-purpose, object-oriented programming language developed by Microsoft. C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows the use of various high-level languages on different computer platforms and architectures. C# combines the power of C++ with the simplicity of Visual Basic, making it an ideal choice for developing a wide range of applications from web services to desktop applications. Key Features of C# Major C# Features Core Language ...
Read MoreHow command line arguments are passed in main method in C#?
The Main() method is the entry point of a C# application and can accept command line arguments through its args parameter. These arguments allow users to pass data to the program when it starts, making applications more flexible and configurable. Syntax The standard syntax for the Main() method with command line arguments is − static void Main(string[] args) The args parameter is a string array that contains all command line arguments passed to the program − // args[0] = first argument // args[1] = second argument // args.Length = total number of ...
Read MoreLifecycle and States of a Thread in C#
Threads are lightweight processes that define a unique flow of control within an application. The lifecycle of a thread starts when an object of the System.Threading.Thread class is created and ends when the thread is terminated or completes execution. Understanding thread states is crucial for effective multithreaded programming in C#. Each thread transitions through various states during its lifetime, and these states determine what operations can be performed on the thread. Thread States Overview The ThreadState enumeration in C# defines the possible states of a thread. Here are the primary states in the lifecycle of a thread ...
Read MoreC# Equivalent to Java's Double Brace Initialization?
Java's Double Brace Initialization is a technique that allows creating and initializing collections in a single expression using an anonymous inner class. C# provides equivalent functionality through Collection Initializers and Object Initializers, which offer cleaner and more efficient syntax. Java Double Brace Initialization In Java, double brace initialization uses nested braces where the outer braces create an anonymous class and the inner braces contain an instance initializer − List list = new List() {{ add("One"); add("Two"); add("Three"); add("Four"); }} ...
Read More