karthikeya Boyini

karthikeya Boyini

1,420 Articles Published

Articles by karthikeya Boyini

Page 15 of 142

How to declare member function in C# interface?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 282 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 497 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 404 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 673 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 421 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 942 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 373 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

C# Program to find a key in a Hashtable

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

A Hashtable in C# is a collection of key-value pairs where each key is unique. To check if a specific key exists in a Hashtable, you can use the Contains() method or ContainsKey() method. Syntax Following is the syntax for creating a Hashtable and checking if a key exists − Hashtable hashtable = new Hashtable(); hashtable.Add(key, value); bool exists = hashtable.Contains(key); Alternatively, you can use ContainsKey() method − bool exists = hashtable.ContainsKey(key); Using Contains() Method The Contains() method returns true if the specified key exists in the Hashtable, otherwise ...

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