Csharp Articles

Page 78 of 196

Mutation Testing in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 303 Views

Mutation testing in C# is a technique for evaluating the quality of your test suite by introducing small changes (mutations) to your source code and checking if your tests can detect these changes. If a test fails when the code is mutated, it indicates the test is effective at catching bugs. The primary purpose of mutation testing is to identify weaknesses in your test suite and improve test coverage quality beyond simple line coverage metrics. How Mutation Testing Works Mutation testing follows a systematic process to evaluate test effectiveness − Mutation Testing ...

Read More

What is the difference between overriding and shadowing in C#?

George John
George John
Updated on 17-Mar-2026 2K+ Views

In C#, overriding and shadowing (also known as method hiding) are two different mechanisms for modifying inherited behavior. Overriding uses the virtual/override keywords to provide specific implementations of base class methods, while shadowing uses the new keyword to hide base class members entirely. Syntax Following is the syntax for method overriding − // Base class public virtual void MethodName() { } // Derived class public override void MethodName() { } Following is the syntax for method shadowing/hiding − // Base class public void MethodName() { } // Derived class public ...

Read More

Properties of the Thread Class

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 6K+ Views

A thread is defined as the execution path of a program. Each thread defines a unique flow of control. The Thread class in C# provides various properties to manage and retrieve information about threads during execution. These properties allow you to control thread behavior, get thread status information, and manage cultural settings. Understanding these properties is essential for effective multithreading in C# applications. Thread Class Properties The following table describes the key properties of the Thread class − Property Description Type CurrentContext Gets the current context in which the ...

Read More

Important Keywords in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 418 Views

C# provides several important keywords that control class behavior, method accessibility, and parameter handling. These keywords include sealed, params, internal, this, and abstract, each serving specific purposes in object-oriented programming. Sealed Keyword The sealed keyword prevents a class from being inherited or a method from being overridden. When applied to a method, it must be an overridden method in a derived class. Syntax public sealed class ClassName { } public sealed override void MethodName() { } Example using System; class Animal { public virtual void ...

Read More

Methods of the Thread Class

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 758 Views

The Thread class in C# provides several methods to control and manage thread execution. The most commonly used methods are Start(), Sleep(), Join(), and Abort() (though Abort() is obsolete in .NET Core and later versions). Commonly Used Thread Methods Method Description Start() Starts the execution of a thread Sleep(int milliseconds) Pauses the current thread for specified time Join() Blocks calling thread until this thread terminates Interrupt() Interrupts a thread in WaitSleepJoin state Using Start() and Join() Methods The Start() method ...

Read More

Lifecycle and States of a Thread in C#

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 642 Views

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 More

How do you make code reusable in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 2K+ Views

To make code reusable in C#, there are several key approaches including interfaces, inheritance, generic classes, and static methods. Among these, interfaces are particularly powerful as they define a contract that multiple classes can implement, enabling polymorphism and flexible code design. Interfaces define properties, methods, and events without providing implementations. The implementing classes must provide the actual functionality, ensuring a consistent structure across different implementations. Syntax Following is the syntax for declaring an interface − public interface IInterfaceName { void MethodName(); int PropertyName { get; set; } } ...

Read More

How to get the nth value of a Fibonacci series using recursion in C#?

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 1K+ Views

The Fibonacci series is a sequence where each number is the sum of the two preceding numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21... In C#, we can use recursion to calculate the nth Fibonacci number by breaking the problem into smaller subproblems. Recursion works by having the method call itself with reduced parameters until it reaches a base case. For Fibonacci, the base cases are F(0) = 0 and F(1) = 1. Syntax Following is the syntax for a recursive Fibonacci method − public int Fibonacci(int n) { if ...

Read More

C# program to find K'th smallest element in a 2D array

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 653 Views

Finding the K'th smallest element in a 2D array requires flattening the array and sorting it to locate the element at the K'th position. This is a common programming problem that demonstrates array manipulation and sorting techniques. Approach The approach involves three main steps − Flatten the 2D array into a 1D array Sort the flattened array in ascending order Access the element at index k-1 (since arrays are zero-indexed) Finding K'th Smallest Element 2D Array ...

Read More

Thread-Safe collections in C#

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 926 Views

Thread-safe collections in C# are specialized data structures designed for concurrent programming. The System.Collections.Concurrent namespace, introduced in .NET Framework 4, provides collections that allow multiple threads to safely add, remove, and access items without external synchronization. These collections use lightweight synchronization mechanisms like SpinLock and SpinWait to achieve thread safety while maintaining high performance and scalability. Thread-Safe Collections Overview Thread A Thread B Thread C Concurrent Collection ...

Read More
Showing 771–780 of 1,951 articles
« Prev 1 76 77 78 79 80 196 Next »
Advertisements