Programming Articles

Page 880 of 2547

Cohesion in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 2K+ Views

Cohesion in C# refers to how closely related and focused the responsibilities within a class or module are. It measures the functional strength and unity of a module's elements. High cohesion means that a class has a single, well-defined purpose with all its methods working together toward that purpose. The greater the cohesion, the better the program design becomes. High cohesion leads to more maintainable, reusable, and understandable code, while low cohesion results in classes that are difficult to maintain and test. Types of Cohesion Cohesion can be categorized from lowest to highest quality − ...

Read More

How to create 1-Tuple or Singleton Tuple in C#?

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 214 Views

The Tuple class in C# represents a 1-tuple or singleton tuple, which is a data structure that holds a single element. Unlike regular variables, tuples provide additional functionality and can be useful when you need to treat a single value as part of a tuple-based system. Syntax Following is the syntax for creating a 1-tuple − Tuple tupleName = new Tuple(value); Accessing the value using the Item1 property − T value = tupleName.Item1; Using 1-Tuple with Integer Values The following example demonstrates creating and using a 1-tuple with an ...

Read More

What does the interface ICloneable do in C#?

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

The ICloneable interface in C# provides a mechanism to create a copy of an existing object, known as cloning. This interface is part of the System namespace and defines a standard way to duplicate objects. Syntax The ICloneable interface contains only one method − public interface ICloneable { object Clone(); } To implement ICloneable, a class must provide the Clone() method − public class MyClass : ICloneable { public object Clone() { // return a copy ...

Read More

How to convert a list to string in C#?

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

In C#, you can convert a List to a string using various methods. The most common and efficient approach is using the string.Join() method, which concatenates all elements of a list into a single string with a specified delimiter. Syntax Following is the syntax for converting a list to string using string.Join() − string result = string.Join(delimiter, list); Where delimiter is the separator between elements, and list is your List collection. Using string.Join() Method The string.Join() method is the most efficient way to convert a list to string. It accepts a delimiter ...

Read More

Matching strings with a wildcard in C#

varma
varma
Updated on 17-Mar-2026 5K+ Views

Wildcard characters in C# allow you to match patterns in strings where some characters are unknown. The most common wildcard is the asterisk (*), which represents zero or more characters. C# provides several ways to implement wildcard matching, including regular expressions and custom methods. Using Regular Expressions for Wildcard Matching Regular expressions are the most powerful way to implement wildcard pattern matching. The pattern \bt\S*s\b matches words that start with 't' and end with 's' − Example using System; using System.Text.RegularExpressions; namespace Demo { public class Program { ...

Read More

C# program to replace n-th character from a given index in a string

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 2K+ Views

In C#, you can replace a character at a specific index in a string by converting the string to a character array, modifying the desired character, and then creating a new string from the modified array. Syntax Following is the basic syntax for replacing a character at a specific index − char[] charArray = originalString.ToCharArray(); charArray[index] = newCharacter; string newString = new string(charArray); Using ToCharArray() Method The most straightforward approach is to convert the string to a character array, replace the character at the desired index, and construct a new string − ...

Read More

Type.GetEnumNames() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 145 Views

The Type.GetEnumNames() method in C# is used to return the names of the members of the current enumeration type as an array of strings. This method is particularly useful when you need to dynamically retrieve all the constant names defined in an enum type at runtime. Syntax Following is the syntax for the GetEnumNames() method − public virtual string[] GetEnumNames(); Return Value This method returns a string array containing the names of the enumeration constants. If the current type is not an enumeration type, it throws an ArgumentException. Using GetEnumNames() with Enum ...

Read More

What does the interface IStructuralComparable do in C#?

Samual Sam
Samual Sam
Updated on 17-Mar-2026 291 Views

The IStructuralComparable interface in C# enables structural comparison of collection objects, meaning it compares elements in sequence rather than using reference equality. This interface was introduced in .NET 4.0 to provide consistent comparison behavior for collections and tuples. Syntax Following is the syntax for the IStructuralComparable interface − public interface IStructuralComparable { int CompareTo(object other, IComparer comparer); } Parameters The CompareTo method accepts the following parameters − other − The object to compare with the current instance. comparer − An IComparer object that defines ...

Read More

C# program to determine if any two integers in array sum to given integer

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 1K+ Views

In this article, we'll learn how to determine if any two integers in an array sum to a given target integer. This is a common programming problem that can be solved using different approaches with varying time complexities. Problem Statement Given an array of integers and a target sum, we need to find if there exist any two numbers in the array that add up to the target value. Using Nested Loops (Brute Force Approach) The simplest approach is to check every possible pair of numbers using nested loops − using System; public ...

Read More

Managed code vs Unmanaged code in C#

Prabhas
Prabhas
Updated on 17-Mar-2026 4K+ Views

In C#, code can be categorized as either managed or unmanaged based on how it is executed and controlled by the .NET runtime environment. Understanding the difference is crucial for C# developers working with system-level programming or interoperability scenarios. Managed Code Managed code is code whose execution is managed by the Common Language Runtime (CLR). The CLR provides automatic memory management, type safety, exception handling, and garbage collection. When you write C# code, it is compiled into Intermediate Language (IL) code, which is then executed by the CLR. Managed Code Execution Flow ...

Read More
Showing 8791–8800 of 25,466 articles
« Prev 1 878 879 880 881 882 2547 Next »
Advertisements