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 Chandu yadav
Page 6 of 81
Default value of bool in C#
The default operator in C# returns the default value for any data type. For the bool type, the default value is false. When a bool variable is declared without initialization, it automatically gets assigned the default value of false. Syntax Following is the syntax for using the default operator with bool − bool variable = default(bool); In C# 7.1 and later, you can also use the simplified syntax − bool variable = default; Using default(bool) Operator The following example demonstrates how to get the default value of bool ...
Read MoreWhat are the C++ features missing in C#?
C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. While C# and C++ share some similarities, there are several key features present in C++ that are either missing or implemented differently in C#. C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ runs on a variety of platforms and provides more direct hardware control compared to C#. Key C++ Features Missing in C# Multiple Inheritance C++ supports multiple inheritance, allowing a class to inherit from multiple base ...
Read MoreC# NullReferenceException
A NullReferenceException is one of the most common runtime exceptions in C#. It occurs when you try to access a member (property, method, or field) of an object reference that is null. When NullReferenceException Occurs This exception is thrown when − You call a method on a null reference You access or modify a property of a null reference You get the length of a null array or string You index into a null array NullReferenceException Flow ...
Read MoreLinkedList AddAfter method in C#
The AddAfter method in C# LinkedList allows you to insert a new node immediately after a specified existing node. This method provides precise control over node placement within the linked list structure. Syntax The AddAfter method has two overloads − public LinkedListNode AddAfter(LinkedListNode node, T value) public void AddAfter(LinkedListNode node, LinkedListNode newNode) Parameters node: The existing node after which the new node will be inserted value: The value to be stored in the new node (first overload) newNode: An existing node to be inserted ...
Read MoreSelection Sort program in C#
Selection Sort is a sorting algorithm that finds the minimum value in the array for each iteration of the loop. Then this minimum value is swapped with the current array element. This procedure is followed until the array is sorted in ascending order. The algorithm divides the array into two parts: a sorted portion (initially empty) and an unsorted portion (initially the entire array). In each iteration, it selects the smallest element from the unsorted portion and moves it to the end of the sorted portion. How Selection Sort Works Selection Sort Process ...
Read MoreThread Synchronization in C#
Thread synchronization in C# is essential for coordinating access to shared resources in multithreaded applications. It prevents race conditions and ensures data consistency by controlling how multiple threads access critical sections of code. C# provides several synchronization mechanisms including the lock statement, Mutex class, and other primitives to manage concurrent thread execution effectively. Syntax Following is the syntax for using the lock statement − lock (syncObject) { // critical section code } Following is the syntax for creating and using a Mutex − private static Mutex mutex ...
Read MoreHow to create a thread in C#?
Threads are lightweight processes that represent independent execution paths within a program. In C#, threads are created using the Thread class from the System.Threading namespace. Creating threads enables concurrent programming, allowing multiple operations to run simultaneously and improving application efficiency. Modern operating systems use threads to implement concurrent programming, which saves CPU cycles and increases application performance by allowing multiple tasks to execute in parallel. Syntax Following is the basic syntax for creating a thread in C# − Thread threadName = new Thread(methodName); threadName.Start(); You can also use a ThreadStart delegate to wrap ...
Read MorePrint with your own font using C#
To print with your own font in C#, you need to construct two essential objects: a FontFamily object and a Font object. The FontFamily object sets the typeface like Arial, Times New Roman, etc., whereas the Font object defines the size, style, and unit of measurement for the font. Syntax Following is the syntax for creating a FontFamily object − FontFamily fontFamily = new FontFamily("FontName"); Following is the syntax for creating a Font object − Font font = new Font(fontFamily, size, style, unit); Parameters The Font constructor accepts the ...
Read MoreC# Program to find the longest string from an array of strings using Lambda Expression
Lambda expressions in C# provide a concise way to write anonymous functions. When working with arrays of strings, you can use lambda expressions with LINQ methods like Aggregate() to perform operations such as finding the longest string. In this example, we'll demonstrate how to find the longest string from an array using the Aggregate() method with a lambda expression. Syntax The Aggregate() method with lambda expression follows this syntax − collection.Aggregate(seed, (accumulator, next) => condition ? next : accumulator, result => transformation) Where − seed − Initial value for comparison accumulator ...
Read MoreWhat are I/O classes in C#?
The System.IO namespace in C# provides a comprehensive collection of classes for performing input/output operations. These classes enable you to work with files, directories, streams, and other data sources efficiently. I/O classes in C# are categorized into several groups based on their functionality − File and Directory Classes These classes provide static methods for basic file and directory operations − using System; using System.IO; class Program { public static void Main() { // File class example string fileName = ...
Read More