Programming Articles

Page 100 of 2547

Difference between Method and Function in C#

George John
George John
Updated on 17-Mar-2026 7K+ Views

In C#, the terms method and function are often used interchangeably, but there is a subtle distinction. A method is a function that belongs to a class or struct, while a function is a more general term for a reusable block of code that performs a specific task. Every C# program has at least one class with a method named Main. Methods are defined within classes and operate on the data and behavior of those classes. Syntax Following is the syntax for defining a method in C# − [access modifier] [return type] MethodName(parameters) { ...

Read More

How to control for loop using break and continue statements in C#?

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

The break and continue statements provide powerful control flow mechanisms within for loops in C#. The break statement terminates the loop entirely, while the continue statement skips the current iteration and moves to the next one. Syntax Following is the syntax for using break statement in a for loop − for (initialization; condition; increment) { if (someCondition) { break; // exits the loop completely } // other statements } Following is the syntax for using continue statement in a ...

Read More

Find frequency of each word in a string in C#

Samual Sam
Samual Sam
Updated on 17-Mar-2026 869 Views

Finding the frequency of each word in a string in C# involves splitting the string into individual words and counting their occurrences. This is a common text processing task useful for data analysis, word clouds, and text mining applications. Using Dictionary for Word Frequency The most efficient approach is to use a Dictionary to store words as keys and their frequencies as values − using System; using System.Collections.Generic; class WordFrequency { public static void Main() { string text = "apple banana apple orange banana apple"; ...

Read More

C# program to create an empty string array

George John
George John
Updated on 17-Mar-2026 4K+ Views

Creating an empty string array in C# is useful when you need to declare an array without initial elements. There are several ways to create an empty string array, each serving different purposes depending on your requirements. Syntax Following are the different ways to create an empty string array − string[] str = new string[] {}; string[] str = new string[0]; string[] str = {}; Using Array Initializer Syntax The most straightforward way to create an empty string array is using the array initializer syntax with empty braces − using System; ...

Read More

C# Program to create a LinkedList

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 347 Views

A LinkedList in C# is a generic collection that stores elements in nodes, where each node contains the data and references to the next and previous nodes. Unlike arrays, LinkedList elements are not stored in contiguous memory locations and allow efficient insertion and removal operations. Syntax Following is the syntax for creating a LinkedList − LinkedList listName = new LinkedList(); You can also create a LinkedList from an existing collection − LinkedList listName = new LinkedList(collection); Creating LinkedList from Array You can create a LinkedList by passing an array ...

Read More

How to find the Sum of two Binary Numbers using C#?

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

Adding two binary numbers in C# involves performing binary arithmetic bit by bit, just like manual addition but working in base-2. The process includes handling carry operations when the sum of bits exceeds 1. Binary addition follows simple rules: 0 + 0 = 0, 0 + 1 = 1, 1 + 0 = 1, and 1 + 1 = 10 (which means 0 with a carry of 1). Syntax Following is the basic approach for binary addition − // Extract rightmost bits bit1 = val1 % 10; bit2 = val2 % 10; // Calculate ...

Read More

C# program to find the index of a word in a string

Ankith Reddy
Ankith Reddy
Updated on 17-Mar-2026 643 Views

Finding the index of a word in a string or array is a common programming task in C#. The Array.IndexOf() method provides an efficient way to locate the position of a specific element within an array of strings. Syntax Following is the syntax for using Array.IndexOf() method − int index = Array.IndexOf(array, searchValue); Parameters array − The one-dimensional array to search searchValue − The object to locate in the array Return Value The method returns the index of the first occurrence of the specified value. If the value is ...

Read More

C# Program to invert the order of elements in a sequence

Samual Sam
Samual Sam
Updated on 17-Mar-2026 256 Views

In C#, you can invert the order of elements in a sequence using several built-in methods. The most common approaches include using Queryable.Reverse() with LINQ, Array.Reverse(), and Enumerable.Reverse(). Each method has its specific use cases and performance characteristics. Syntax Following is the syntax for using Queryable.Reverse() method − IQueryable result = sequence.AsQueryable().Reverse(); Following is the syntax for using Array.Reverse() method − Array.Reverse(array); Following is the syntax for using Enumerable.Reverse() method − IEnumerable result = sequence.Reverse(); Using Queryable.Reverse() Method The Queryable.Reverse() method returns an IQueryable that ...

Read More

Decimal.ToString() Method in C#

AmitDiwan
AmitDiwan
Updated on 17-Mar-2026 294 Views

The Decimal.ToString() method in C# is used to convert the numeric value of a decimal instance to its equivalent string representation. This method provides various overloads to format the decimal value according to specific requirements. Syntax Following is the basic syntax for Decimal.ToString() method − public override string ToString(); The method also has overloaded versions for custom formatting − public string ToString(string format); public string ToString(IFormatProvider provider); public string ToString(string format, IFormatProvider provider); Parameters format − A standard or custom numeric format string (optional). provider − An object ...

Read More

What does Array.IsSynchronized property of array class do in C#?

Arjun Thakur
Arjun Thakur
Updated on 17-Mar-2026 205 Views

The Array.IsSynchronized property in C# gets a boolean value indicating whether access to the Array is synchronized (thread-safe). This property is part of the ICollection interface implementation and helps determine if an array can be safely accessed by multiple threads simultaneously. For standard C# arrays, this property always returns false, meaning that arrays are not inherently thread-safe. When multiple threads need to access the same array, you must implement your own synchronization using the SyncRoot property or other synchronization mechanisms. Syntax Following is the syntax for the Array.IsSynchronized property − public bool IsSynchronized { get; ...

Read More
Showing 991–1000 of 25,467 articles
« Prev 1 98 99 100 101 102 2547 Next »
Advertisements