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
Programming Articles
Page 808 of 2547
Naming Conventions in C#
Naming conventions in C# help maintain code readability and consistency across projects. Following standardized naming patterns makes your code more professional and easier to understand for other developers. Class Naming Conventions A class definition starts with the class keyword followed by the class name, enclosed by curly braces. The following conventions apply to class names. Pascal Casing Class names should use PascalCasing, where the first letter of each word is capitalized − public class EmployeeDetails { } public class BankAccount { } public class CustomerOrderHistory { } Noun or Noun Phrases ...
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 MoreRemove duplicates from a List in C#
Removing duplicates from a List in C# is a common task when working with collections. There are several approaches to accomplish this, with Distinct() being the most straightforward method. The Distinct() method uses LINQ to filter out duplicate elements based on their default equality comparison. Syntax Following is the syntax for using Distinct() to remove duplicates − List uniqueList = originalList.Distinct().ToList(); For custom equality comparison − List uniqueList = originalList.Distinct(comparer).ToList(); Using Distinct() Method The Distinct() method from LINQ is the simplest way to remove duplicates from a list. It ...
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 MoreWhat are all the possible C# array initialization syntaxes?
C# provides multiple ways to initialize arrays, giving you flexibility in how you declare and populate arrays with values. Each syntax has its specific use cases depending on whether you know the array size in advance or want to provide initial values immediately. Array Initialization Syntax Options Explicit Size with Values You can specify the array size explicitly along with initial values − int[] marks = new int[5] { 99, 98, 92, 97, 95 }; Implicit Size with Values The array size can be inferred from the number of elements provided − ...
Read MoreHow to declare member function in C# interface?
To declare member functions in C# interfaces, you define method signatures without implementations. The implementing class must provide the actual method bodies using the public access modifier. Syntax Following is the syntax for declaring member functions in an interface − public interface InterfaceName { ReturnType MethodName(parameters); void AnotherMethod(); } The implementing class must provide implementations for all interface methods − public class ClassName : InterfaceName { public ReturnType MethodName(parameters) { // implementation } ...
Read MoreWay to increment a character in C#
In C#, you can increment a character by using the increment operator ++. When you increment a character, it moves to the next character in the ASCII table sequence. Syntax Following is the syntax for incrementing a character − char ch = 'K'; ch++; // moves to next ASCII character You can also use the compound assignment operator − ch += 1; // equivalent to ch++ How It Works Characters in C# are stored as numeric values based on their ASCII or Unicode code points. When you ...
Read MoreNull List in C#
A null list in C# refers to a List reference that points to nothing instead of an actual List object. This is different from an empty list, which is an initialized List with zero elements. Understanding null lists is crucial for avoiding NullReferenceException errors in your applications. Syntax To declare a null list − List listName = null; To check if a list is null − if (listName == null) { // handle null case } Creating and Checking Null Lists When you declare a List ...
Read MoreMath.Cos() Method in C#
The Math.Cos() method in C# returns the cosine of a specified angle. The angle must be provided in radians, not degrees. This method is part of the System.Math class and is commonly used in mathematical calculations, graphics programming, and trigonometric operations. Syntax Following is the syntax for the Math.Cos() method − public static double Cos(double val); Parameters val − A double value representing the angle in radians whose cosine is to be calculated. Return Value The method returns a double value representing the cosine of the specified ...
Read MoreMathF.Abs() Method in C# with Examples
The MathF.Abs() method in C# is used to return the absolute value of a float number. The absolute value represents the non-negative value of a number without regard to its sign. For example, the absolute value of both -5.5f and 5.5f is 5.5f. This method is part of the System namespace and is specifically designed for float operations, providing better performance than the generic Math.Abs() method when working with single-precision floating-point numbers. Syntax Following is the syntax for the MathF.Abs() method − public static float Abs(float val); Parameters val − A ...
Read More