Programming Articles

Page 863 of 2547

How to assign same value to multiple variables in single statement in C#?

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

In C#, you can assign the same value to multiple variables in a single statement using the assignment operator. This technique is called chained assignment and works because the assignment operator returns the assigned value. Syntax Following is the syntax for assigning the same value to multiple variables − variable1 = variable2 = variable3 = value; The assignment is evaluated from right to left, so value is first assigned to variable3, then that result is assigned to variable2, and finally to variable1. How It Works The assignment operator (=) in C# returns ...

Read More

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

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 371 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 534 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

What is the C# equivalent to Java's isInstance()?

George John
George John
Updated on 17-Mar-2026 951 Views

Java's isInstance() method determines if a specified object is assignment-compatible with the object represented by a class. In C#, there are several equivalent approaches to achieve the same functionality for type checking and instance validation. C# Equivalents to Java's isInstance() The most common C# equivalents are the is operator, IsAssignableFrom() method, and IsInstanceOfType() method. Each serves different use cases depending on whether you're working with objects, types, or need runtime type checking. Using the 'is' Operator The simplest and most commonly used equivalent is the is operator − bool result = (object is ClassName); ...

Read More

How to remove items from a list in C#?

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 528 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

Compound assignment operators in C#

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

Compound assignment operators in C# provide a shorter syntax to perform an operation and assign the result back to the same variable. These operators combine arithmetic, bitwise, or shift operations with assignment in a single step. For example, x += 5 is equivalent to x = x + 5, but more concise and readable. Syntax The general syntax for compound assignment operators is − variable operator= value; This is equivalent to − variable = variable operator value; Types of Compound Assignment Operators Operator Name Equivalent ...

Read More

C# program to print all sublists of a list

karthikeya Boyini
karthikeya Boyini
Updated on 17-Mar-2026 755 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

Large Fibonacci Numbers in C#

Chandu yadav
Chandu yadav
Updated on 17-Mar-2026 555 Views

To display large Fibonacci numbers in C#, we need to handle numbers that exceed the range of standard integer types. The Fibonacci sequence grows exponentially, so after just 40-50 terms, the values become too large for int or even long data types. For truly large Fibonacci numbers, we use the BigInteger class from System.Numerics, which can handle arbitrarily large integers without overflow. Syntax Following is the basic syntax for generating Fibonacci numbers − int val1 = 0, val2 = 1, val3; for (int i = 2; i < n; i++) { val3 ...

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

Constructor Overloading in C#

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

Constructor overloading in C# allows you to define multiple constructors within the same class, each with different parameters. This provides flexibility in object initialization, allowing different ways to create instances of the same class. Constructor overloading follows the same rules as method overloading − constructors must have different parameter lists (number, type, or order of parameters). Syntax Following is the syntax for constructor overloading − public class ClassName { public ClassName() { // default constructor } ...

Read More
Showing 8621–8630 of 25,466 articles
« Prev 1 861 862 863 864 865 2547 Next »
Advertisements