karthikeya Boyini

karthikeya Boyini

1,420 Articles Published

Articles by karthikeya Boyini

Page 22 of 142

How do I sort a two-dimensional array in C#

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

Sorting a two-dimensional array in C# can be accomplished using several approaches. The most common methods include sorting individual rows using nested loops with bubble sort, using Array.Sort() for jagged arrays, or converting to a one-dimensional array for sorting. Syntax For sorting rows in a 2D array using nested loops − for (int i = 0; i < arr.GetLength(0); i++) { for (int j = 0; j < arr.GetLength(1) - 1; j++) { for (int k = 0; k < arr.GetLength(1) - j - 1; k++) { ...

Read More

What is the difference between declaration and definition in C#?

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

In C#, declaration means specifying the type and name of a variable, method, or class without providing an initial value or implementation. Definition (or initialization) means providing an actual value or implementation to what was declared. This distinction applies to variables, arrays, methods, and classes. Understanding the difference helps write cleaner code and avoid compilation errors. Syntax Following is the syntax for declaration − datatype variableName; Following is the syntax for definition/initialization − variableName = value; // or combined declaration and initialization datatype variableName = value; Variable Declaration vs ...

Read More

What are the escape sequences supported by C#?

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

Escape sequences in C# are special character combinations that start with a backslash (\) and represent characters that are difficult or impossible to type directly. These sequences allow you to include special characters like newlines, tabs, quotes, and control characters in your strings. Syntax Following is the syntax for escape sequences in C# − string text = "HelloWorld"; // represents a newline char tab = '\t'; // \t represents a tab character Common Escape Sequences ...

Read More

C# Program to convert a Double value to an Int64 value

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

To convert a Double value to an Int64 value, use the Convert.ToInt64() method. This method performs a rounded conversion from a 64-bit floating-point number to a 64-bit signed integer. Int64 represents a 64-bit signed integer and is equivalent to the long data type in C#. The conversion truncates the decimal portion and rounds to the nearest integer value. Syntax Following is the syntax for converting a double to Int64 − long result = Convert.ToInt64(doubleValue); Parameters doubleValue − A double-precision floating-point number to be converted. Return Value Returns a ...

Read More

How do you use 'foreach' statement for accessing array elements in C#

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

The foreach statement in C# provides a simple way to iterate through all elements in an array without needing to manage index variables. Unlike a traditional for loop, foreach automatically accesses each element in sequence. Syntax Following is the syntax for using foreach with arrays − foreach (dataType variable in arrayName) { // code to process each element } The foreach loop automatically iterates through each element, assigning the current element's value to the specified variable. Using foreach with Arrays Example using System; class MyArray { ...

Read More

What are dynamic arrays in C#?

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

Dynamic arrays are growable arrays that can resize themselves during runtime, providing a significant advantage over static arrays which have a fixed size. In C#, you can create dynamic arrays using collections like ArrayList and the more modern List. These dynamic collections allow automatic memory allocation, resizing, adding, searching, and sorting items efficiently. The ArrayList stores objects of any type, while List is type-safe and performs better. Syntax Following is the syntax for creating an ArrayList − ArrayList arrayList = new ArrayList(); arrayList.Add(item); Following is the syntax for creating a generic List − ...

Read More

Important Keywords in C#

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

C# provides several important keywords that control class behavior, method accessibility, and parameter handling. These keywords include sealed, params, internal, this, and abstract, each serving specific purposes in object-oriented programming. Sealed Keyword The sealed keyword prevents a class from being inherited or a method from being overridden. When applied to a method, it must be an overridden method in a derived class. Syntax public sealed class ClassName { } public sealed override void MethodName() { } Example using System; class Animal { public virtual void ...

Read More

C# program to count the occurrences of each character

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

Counting character occurrences in a string is a common programming task in C#. This can be accomplished using various approaches, from basic loops to modern LINQ methods and dictionary-based solutions. Using Basic Loop with String Manipulation The first approach uses a while loop and string replacement to count occurrences − using System; public class Demo { public static void Main() { string str = "Website"; Console.WriteLine("String: " + str); ...

Read More

C# Program to find the largest element from an array

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

Finding the largest element in an array is a common programming task in C#. There are multiple approaches to achieve this, ranging from using built-in LINQ methods to implementing custom logic with loops. Using LINQ Max() Method The simplest approach is to use the Max() method from the System.Linq namespace − using System; using System.Linq; class Demo { static void Main() { int[] arr = { 20, 50, -35, 25, 60 }; int largest = ...

Read More

Implicit conversion from 32-bit unsigned integer (UInt) to Decimal in C#

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

Implicit conversion from a 32-bit unsigned integer (uint) to decimal in C# happens automatically when you assign a uint value to a decimal variable. This conversion is considered safe because decimal can represent all possible uint values without any loss of precision. Syntax Following is the syntax for implicit conversion from uint to decimal − uint uintValue = someValue; decimal decimalValue = uintValue; // implicit conversion How It Works The C# compiler automatically performs this conversion because: uint ranges from 0 to 4, 294, 967, 295 decimal can ...

Read More
Showing 211–220 of 1,420 articles
« Prev 1 20 21 22 23 24 142 Next »
Advertisements