karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 15 of 143

Remove duplicates from a List in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 7K+ Views

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 More

How to declare member function in C# interface?

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

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 More

Assertions in C#

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 2K+ Views

Assertions in C# are debugging tools used to check assumptions in your code during development. They have two main arguments − a boolean expression that should evaluate to true, and an optional message to display if the assertion fails. Assertions are particularly useful in large and complex programs to quickly identify logic errors that may arise when code is modified. They help catch bugs early in the development process. Syntax Following is the syntax for using Debug.Assert() − Debug.Assert(condition); Debug.Assert(condition, "Error message"); Debug.Assert(condition, "Error message", "Detailed message"); Key Rules Assertions ...

Read More

C# Program to Subtract Two TimeSpan

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

In C#, the TimeSpan structure represents a time interval and provides methods to perform arithmetic operations. To subtract one TimeSpan from another, you can use the Subtract() method or the subtraction operator (-). Syntax Following is the syntax for subtracting TimeSpan objects using the Subtract() method − TimeSpan result = timeSpan1.Subtract(timeSpan2); Following is the syntax using the subtraction operator − TimeSpan result = timeSpan1 - timeSpan2; Using Subtract() Method The Subtract() method returns a new TimeSpan that represents the difference between two TimeSpan values − using System; ...

Read More

Long Date ("D") Format Specifier in C#

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

The "D" format specifier in C# represents the long date format pattern. It displays dates in a culture-specific long format, showing the full day name, month name, day, and year without time information. The format string is defined by the culture's DateTimeFormatInfo.LongDatePattern property and varies based on the specified culture. Syntax Following is the syntax for using the "D" format specifier − DateTime.ToString("D") DateTime.ToString("D", CultureInfo) The default custom format string for English (US) culture is − dddd, dd MMMM yyyy Using "D" Format with Default Culture Example ...

Read More

Overriding in C#

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

Method overriding in C# enables runtime polymorphism by allowing a derived class to provide a specific implementation of a method that is already defined in its base class. This is achieved using the virtual keyword in the base class and the override keyword in the derived class. Overriding is essential for implementing dynamic polymorphism, where the method to be called is determined at runtime based on the actual object type rather than the reference type. Syntax Following is the syntax for method overriding using virtual and override keywords − // Base class with virtual method ...

Read More

C# program to Loop over a two dimensional array

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 5K+ Views

A two-dimensional array in C# stores elements in a grid format with rows and columns. To loop through all elements, you need to iterate through both dimensions using nested loops. Syntax Following is the syntax for declaring a two-dimensional array − dataType[,] arrayName = new dataType[rows, columns]; Following is the syntax for looping through a two-dimensional array using nested for loops − for (int i = 0; i

Read More

Addition and Concatenation in C#

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

In C#, addition refers to mathematical operations with numeric types, while concatenation refers to joining strings together. The + operator can perform both operations depending on the operand types, and C# provides several methods for string concatenation. Syntax Following is the syntax for numeric addition − int result = number1 + number2; Following is the syntax for string concatenation using the + operator − string result = string1 + string2; Following is the syntax for string concatenation using String.Concat() method − string result = String.Concat(string1, string2); ...

Read More

How to swap two numbers without using a temp variable in C#

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

Swapping two numbers without using a temporary variable can be achieved using different techniques in C#. These methods eliminate the need for extra memory allocation and demonstrate clever mathematical and bitwise operations. Using Arithmetic Operations The most common approach uses addition and subtraction operations to swap values − val1 = val1 + val2; val2 = val1 - val2; val1 = val1 - val2; Example using System; class Program { static void Main(string[] args) { int val1, val2; ...

Read More

How to define a single-dimensional array in C Sharp?

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

An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations. A single-dimensional array in C# is a linear collection of elements of the same data type. It allows you to store multiple values in a single variable and access them using an index. Syntax Following is the syntax for declaring a single-dimensional array − datatype[] arrayName = new datatype[size]; Following is the syntax for initializing an array with ...

Read More
Showing 141–150 of 1,421 articles
« Prev 1 13 14 15 16 17 143 Next »
Advertisements