karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 23 of 143

Print a 2 D Array or Matrix in C#

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

A 2D array or matrix in C# is a data structure that stores elements in rows and columns. To print a 2D array, you need to use nested loops to iterate through each row and column, displaying the elements in a formatted manner. Syntax Following is the syntax for declaring a 2D array − dataType[, ] arrayName = new dataType[rows, columns]; Following is the syntax for printing a 2D array using nested loops − for (int i = 0; i < rows; i++) { for (int j = ...

Read More

Complex Numbers in C#

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

A complex number in C# consists of two components: a real part and an imaginary part. For example, in the complex number 7+5i, the real part is 7 and the imaginary part is 5 (the coefficient of i). C# allows you to create custom data structures to represent complex numbers using struct and implement mathematical operations using operator overloading. Syntax Following is the syntax for creating a complex number structure − public struct Complex { public double real; public double imaginary; public ...

Read More

How to access elements from a rectangular array in C#?

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

To access elements from a rectangular array in C#, you need to specify the row and column indices using square brackets. Multi-dimensional arrays are also called rectangular arrays because they form a rectangular structure with fixed dimensions. Syntax Following is the syntax for accessing elements in a rectangular array − dataType[, ] arrayName = new dataType[rows, columns]; arrayName[rowIndex, columnIndex] = value; To retrieve an element − dataType element = arrayName[rowIndex, columnIndex]; Rectangular Array Structure Columns 0 1 2 ...

Read More

How to print all the Armstrong Numbers from 1 to 1000 using C#?

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

An Armstrong number (also called a narcissistic number) is a number that equals the sum of its own digits raised to the power of the number of digits. For 3-digit numbers, each digit is cubed and summed. For example, 153 is an Armstrong number because 1³ + 5³ + 3³ = 1 + 125 + 27 = 153. To find all Armstrong numbers from 1 to 1000, we need to check each number by extracting its digits, calculating the sum of cubes, and comparing it with the original number. Algorithm The steps to identify Armstrong numbers are ...

Read More

How to remove items from a list in C#?

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

In C#, there are several ways to remove items from a List. The most commonly used methods are Remove(), RemoveAt(), RemoveAll(), and Clear(). Each method serves different purposes depending on whether you want to remove by value, by index, by condition, or all items. Syntax Following are the common syntaxes for removing items from a list − // Remove by value list.Remove(item); // Remove by index list.RemoveAt(index); // Remove all items matching a condition list.RemoveAll(predicate); // Remove all items list.Clear(); Using Remove() Method The Remove() method removes the first occurrence ...

Read More

C# program to print all sublists of a list

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

A sublist (or subsequence) of a string contains characters from the original string in the same order, but not necessarily consecutive. For example, from the string "xyz", possible sublists include "x", "xy", "xz", "y", "yz", "z", and "xyz". This program generates all possible sublists of a given string by building them incrementally using nested loops and dynamic list operations. How the Algorithm Works The algorithm processes each character of the input string and creates new sublists by combining existing sublists with the current character. It maintains a list that grows with each iteration, containing all possible sublists ...

Read More

How to print the contents of array horizontally using C#?

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

Printing array contents horizontally in C# means displaying all elements in a single line, separated by spaces or other delimiters. This is useful for creating formatted output where elements appear side by side rather than vertically. When you print an array using a regular loop with Console.WriteLine(), each element appears on a new line. To display elements horizontally, C# provides several approaches. Syntax Using string.Join() method − string.Join(separator, array) Using Console.Write() in a loop − for (int i = 0; i < array.Length; i++) { Console.Write(array[i] + ...

Read More

Constructors in C#

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

A constructor in C# is a special method that gets invoked automatically when an object is created. The constructor has the same name as the class and is used to initialize the object's state. Constructors do not have a return type, not even void. Syntax Following is the basic syntax for declaring a constructor − public class ClassName { public ClassName() { // constructor body } } Types of Constructors C# supports several types of constructors − Default ...

Read More

Lambda Expressions in C#

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

A lambda expression in C# is an anonymous function that provides a concise way to write inline functions. Lambda expressions use the => operator, read as "goes to", which separates the input parameters from the expression body. Lambda expressions are commonly used with LINQ methods, event handlers, and delegates to create short, readable code without defining separate methods. Syntax Following is the basic syntax for lambda expressions − (input-parameters) => expression For single parameter, parentheses are optional − x => x * 2 For multiple statements, use curly braces ...

Read More

C# Program to remove whitespaces in a string

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

In C#, there are several ways to remove whitespaces from a string. You can remove all spaces, only leading and trailing spaces, or all types of whitespace characters including tabs and newlines. Using String.Replace() Method The Replace()

Read More
Showing 221–230 of 1,421 articles
« Prev 1 21 22 23 24 25 143 Next »
Advertisements