Csharp Articles

Page 11 of 196

Delegates vs Interfaces in C#

Siva Sai
Siva Sai
Updated on 17-Mar-2026 2K+ Views

Delegates and interfaces are both powerful constructs in C# that allow for flexible and extensible code. While they serve different purposes, they can sometimes be used to achieve similar ends, leading to confusion about when to use one over the other. This article will elucidate the differences and similarities between delegates and interfaces, and provide guidelines for their use. Syntax Following is the syntax for declaring a delegate − public delegate returnType DelegateName(parameters); Following is the syntax for declaring an interface − public interface IInterfaceName { returnType MethodName(parameters); } ...

Read More

C# program to count prime numbers in an array

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 13K+ Views

Prime numbers are natural numbers greater than 1 with exactly two factors: 1 and themselves. Examples include 2, 3, 5, 7, 11, 13, and so on. The smallest prime number is 2, which is also the only even prime number. Problem Description We are given an array and need to find the count of prime numbers present in that array using C#. Below are examples to understand the problem − Examples Input: array = {3, 6, 12, 7, 9, 11} Output: Count = 3 (prime numbers: 3, 7, 11) Explanation: The numbers 3, 7, and 11 ...

Read More

C# Program to Remove Duplicates from an Array

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 7K+ Views

In this article, we will explore how to remove duplicate elements from an array in C# using different approaches. Removing duplicates is a common programming task that helps maintain data integrity and optimize storage. What are Duplicate Elements in an Array? Duplicate elements are values that appear more than once in an array. When removing duplicates, we keep only one occurrence of each unique value, creating a new array with distinct elements. Examples Input: array = {1, 1, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6} Output: array = {1, 2, 3, 4, ...

Read More

Remove all odd numbers from an array in C#

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 4K+ Views

Natural numbers are a set of positive integers, which are commonly used for counting and ordering. They begin from 1 and continue infinitely. In some contexts, it may also include 0. Here, we are going to learn about different approaches to removing all odd numbers from a given array using C#. Problem Description We are given an array, and we need to remove all the odd numbers from it. The resulting array should only contain even numbers. Example 1 Input: array = {1, 2, 3, 4, 5, 6} Output: {2, 4, 6} Explanation: ...

Read More

Find the sum of cubes of the first N natural numbers in C#

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 4K+ Views

We are given a number N, and we need to calculate the sum of the cubes of the first N natural numbers. In this article, we are going to learn how we can find the sum of cubes of the first N natural numbers in C#. Problem Description The task is to compute the sum: 1³ + 2³ + 3³ + ... + N³ for a given positive integer N. Example 1 Input: N = 3 Output: 36 Explanation: The cubes of the first 3 natural numbers are − 1³ = 1, ...

Read More

Convert a number to Roman numerals in C#

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 4K+ Views

Converting a number to Roman numerals in C# is a common programming problem that involves mapping integer values to their corresponding Roman numeral representations. Roman numerals use specific symbols like I, V, X, L, C, D, and M to represent numbers. Roman Numeral System Roman numerals follow specific rules where certain combinations represent subtraction (like IV for 4, IX for 9). The key is to use a mapping of values in descending order, including these special cases − Roman Numeral Values M = 1000 ...

Read More

C# Program to Find the Sum of First N Natural Numbers

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 6K+ Views

We are given a number N, and we need to calculate the sum of the first N natural numbers. Natural numbers are positive integers starting from 1 (i.e., 1, 2, 3, 4, 5, ...). In this article, we are going to learn how we can find the sum of the first N natural numbers in C#. Sum of First N Natural Numbers N = 5 1 2 3 4 ...

Read More

C# program to find first set bit

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 4K+ Views

In this problem, we are given a number n, and we need to find the position of the first set bit (1-bit) in its binary representation. The position is counted from the right, starting at 1. In this article, we are going to discuss different approaches to solving this problem using C#. Finding First Set Bit Position Number: 18 Binary: 1 0 0 1 0 ...

Read More

Maximum Subarray Sum - Kadane Algorithm using C#

AYUSH MISHRA
AYUSH MISHRA
Updated on 17-Mar-2026 3K+ Views

The Maximum Subarray Sum problem involves finding the contiguous subarray within a given array of integers that has the largest sum. Kadane's Algorithm is the most efficient approach to solve this problem in linear time. Given an array that may contain both positive and negative integers, we need to find the maximum sum of any contiguous subarray. Here is an example − Input: arr = [1, -2, 3, 4, -1, 2, 1, -5, 4] Maximum Sum Subarray: [3, 4, -1, 2, 1] Sum = 3 + 4 + (-1) + 2 + 1 = 9 ...

Read More

Char.IsDigit() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 2K+ Views

The Char.IsDigit() method in C# determines whether a specified Unicode character is categorized as a decimal digit. This method is useful for validating input, parsing strings, and filtering numeric characters from text. Syntax Following is the syntax for the Char.IsDigit() method − public static bool IsDigit(char ch); Parameters ch − The Unicode character to evaluate. Return Value Returns true if the character is a decimal digit; otherwise, false. Using Char.IsDigit() with Different Characters Example 1 - Testing Non-Digit Characters using System; public ...

Read More
Showing 101–110 of 1,951 articles
« Prev 1 9 10 11 12 13 196 Next »
Advertisements