karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 9 of 143

How to write the first program in C#?

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

Writing your first program in C# is the foundation of learning this powerful programming language. A C# program consists of several key components that work together to produce output. Let's explore the structure and elements of a basic C# program. Syntax Following is the basic structure of a C# program − using System; namespace NamespaceName { class ClassName { static void Main(string[] args) { // Program logic here ...

Read More

Flow control in try catch finally in C#

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

The flow control in try-catch-finally blocks in C# follows a specific execution order depending on whether exceptions occur. Understanding this flow is crucial for proper error handling and resource management in your applications. Syntax Following is the syntax for try-catch-finally blocks − try { // Code that may throw an exception } catch (ExceptionType e) { // Exception handling code } finally { // Code that always executes } Flow Control Rules The try block executes first and contains code that might ...

Read More

C# program to find the index of an element in a List

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

In C#, you can find the index of an element in a List using the IndexOf() method. This method returns the zero-based index of the first occurrence of the specified element, or -1 if the element is not found. Syntax Following is the syntax for the IndexOf() method − int IndexOf(T item) int IndexOf(T item, int startIndex) int IndexOf(T item, int startIndex, int count) Parameters item: The element to locate in the list. startIndex: The zero-based starting index of the search (optional). count: The number of elements to search (optional). ...

Read More

How to declare and initialize a dictionary in C#?

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

A Dictionary in C# is a collection that stores key-value pairs, where each key must be unique. It is part of the System.Collections.Generic namespace and provides fast lookups based on keys. Syntax Following is the syntax for declaring and initializing a Dictionary − Dictionary dictionaryName = new Dictionary(); Where TKey is the type of the key and TValue is the type of the value. You can also use the interface type for more flexibility − IDictionary dictionaryName = new Dictionary(); Using Dictionary.Add() Method The Add() method allows you ...

Read More

C# Program to find the smallest element from an array using Lambda Expressions

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

Lambda expressions in C# provide a concise way to write anonymous functions. When combined with LINQ methods like Min(), they offer powerful tools for array operations. This article demonstrates how to find the smallest element from an array using lambda expressions. Syntax The basic syntax for using Min() with lambda expressions − array.Min() // finds minimum value directly array.Min(element => expression) // finds minimum based on expression Using Min() Without Lambda Expression For ...

Read More

What are abstract classes in C#?

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

An abstract class in C# is a class that cannot be instantiated directly and contains one or more abstract methods that must be implemented by derived classes. Abstract classes provide a common base with shared functionality while requiring derived classes to implement specific methods with their own specialized behavior. Abstract classes are declared using the abstract keyword and serve as blueprints for related classes that share common characteristics but need different implementations for certain operations. Syntax Following is the syntax for declaring an abstract class with abstract methods − abstract class ClassName { ...

Read More

Private Variables in C#

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

The private access specifier in C# allows a class to hide its member variables and member functions from other functions and objects. Only methods of the same class can access its private members. Even an instance of a class cannot access its private members directly from outside the class. Syntax Following is the syntax for declaring a private variable − private dataType variableName; For example − private double length; private int count; private string name; Key Rules of Private Variables Private members can only be accessed within ...

Read More

C# program to get the List of keys from a Dictionary

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

In C#, you can extract all the keys from a Dictionary as a List using the Keys property. This is useful when you need to work with dictionary keys as a separate collection or perform operations like sorting, filtering, or iteration. Syntax Following is the syntax to get keys from a Dictionary − Dictionary dictionary = new Dictionary(); List keys = new List(dictionary.Keys); You can also use LINQ to convert keys to a List − List keys = dictionary.Keys.ToList(); Using Dictionary.Keys Property The Keys property returns a collection of ...

Read More

How to declare and initialize constant strings in C#?

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

To declare a constant string in C#, use the const keyword. Constants are immutable values that are set at compile-time and cannot be changed during program execution. Once initialized, attempting to modify a constant will result in a compile-time error. Syntax Following is the syntax for declaring and initializing a constant string − const string constantName = "value"; Constants must be initialized at the time of declaration and the value must be a compile-time constant expression. Key Rules for Constants Constants must be initialized at declaration − you cannot declare ...

Read More

Insert more than one element at once in a C# List

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

The InsertRange() method in C# allows you to insert multiple elements into a List at a specified position. This method is useful when you need to add a collection of elements at once rather than adding them one by one. Syntax Following is the syntax for the InsertRange() method − public void InsertRange(int index, IEnumerable collection) Parameters index − The zero-based index at which the new elements should be inserted. collection − The collection whose elements should be inserted into the List. The collection itself cannot be null, but ...

Read More
Showing 81–90 of 1,421 articles
« Prev 1 7 8 9 10 11 143 Next »
Advertisements