karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 18 of 143

Important Keywords in C#

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

C# program to count total set bits in a number

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

A set bit refers to a bit that has a value of 1 in the binary representation of a number. Counting set bits is a common programming problem that involves examining each bit position to determine how many are set to 1. For example, the number 11 in decimal has the binary representation 1011, which contains 3 set bits (three 1s). Approach The most straightforward approach uses bitwise operations to examine each bit − Use the bitwise AND operator (&) with 1 to check if the least significant bit is set Right-shift ...

Read More

What are the differences between ref and out parameters in C#?

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

The ref and out parameters in C# are both used to pass arguments by reference, but they have distinct behaviors and use cases. Both allow methods to modify the original variable, but they differ in initialization requirements and intended purposes. Syntax Following is the syntax for declaring ref parameters − public void MethodName(ref int parameter) { // parameter can be read and modified } Following is the syntax for declaring out parameters − public void MethodName(out int parameter) { // parameter must be assigned ...

Read More

Group by Operator in C#

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

The Group By operator in C# is used to group elements in a collection based on a specified key. It separates the results into groups where each group contains elements that share the same key value. Syntax Following is the syntax for using Group By with LINQ query syntax − var result = from element in collection group element by keySelector; Following is the syntax for using Group By with method syntax − var result = collection.GroupBy(keySelector); ...

Read More

Extracting MAC address using C#

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

A MAC address (Media Access Control address) is a unique identifier assigned to network interfaces for communications at the data link layer of a network segment. It serves as a network address for most IEEE 802 network technologies, including Ethernet, Wi-Fi, and Bluetooth. In C#, you can extract MAC addresses using the NetworkInterface class from the System.Net.NetworkInformation namespace. This class provides methods to enumerate all network interfaces on the local computer and retrieve their physical addresses. Syntax Following is the syntax for getting all network interfaces − NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); Following is ...

Read More

How to iterate any Map in C#

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

C# doesn't have a built-in Map type like Java. Instead, C# uses Dictionary to achieve the same functionality. A Dictionary stores key-value pairs and provides several ways to iterate through its contents. Syntax Following is the syntax for creating a Dictionary − Dictionary dictionary = new Dictionary(); Following are the common iteration patterns − // Iterate over keys foreach (var key in dictionary.Keys) { } // Iterate over values foreach (var value in dictionary.Values) { } // Iterate over key-value pairs foreach (var kvp in dictionary) { } ...

Read More

C# Program to display name of Current Thread

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

To display the name of the current thread in C#, use the Name property of the Thread.CurrentThread object. This property allows you to both set and retrieve the name of the currently executing thread. Syntax Following is the syntax to get the current thread − Thread thread = Thread.CurrentThread; Following is the syntax to set and get the thread name − thread.Name = "ThreadName"; string currentName = thread.Name; Using Thread.CurrentThread Property The Thread.CurrentThread property returns a reference to the currently executing thread. You can then use the Name property ...

Read More
Showing 171–180 of 1,421 articles
« Prev 1 16 17 18 19 20 143 Next »
Advertisements