Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Arjun Thakur
Page 14 of 75
Variable Arguments (Varargs) in C#
The params keyword in C# allows a method to accept a variable number of arguments of the same type. This feature, known as variable arguments or varargs, enables you to call a method with any number of parameters without creating an array explicitly. Syntax Following is the syntax for declaring a method with variable arguments − public static returnType MethodName(params type[] parameterName) { // method body } The params keyword must be the last parameter in the method signature, and only one params parameter is allowed per method. Key Rules ...
Read MoreEvents vs Delegates in C#
In C#, both delegates and events provide mechanisms for method invocation, but they serve different purposes and have distinct characteristics. Events are built on top of delegates but provide additional safety and encapsulation features that make them more suitable for notification scenarios. Syntax Following is the syntax for declaring a delegate − public delegate void DelegateName(parameters); Following is the syntax for declaring an event − public delegate void DelegateName(parameters); public event DelegateName EventName; Delegates in C# A delegate is a reference type that holds references to methods with the ...
Read MoreHow to check if an item exists in a C# list collection?
In C#, you can check if an item exists in a List collection using several methods. The most common approach is the Contains() method, which returns true if the item is found and false otherwise. Syntax Following is the syntax for the Contains() method − bool Contains(T item) Parameters item − The object to locate in the list. The value can be null for reference types. Return Value Returns true if the item is found in the list; otherwise, false. Using Contains() Method Example using ...
Read MoreSet tuple as a method parameter in C#
In C#, you can pass tuples as method parameters to group related values together. This approach is useful when you need to pass multiple values to a method without creating a separate class or using multiple parameters. Syntax Following is the syntax for creating a tuple and passing it as a method parameter − // Creating a tuple var tuple = Tuple.Create(value1, value2, value3); // Method with tuple parameter static void MethodName(Tuple tuple) { // Access tuple items using Item1, Item2, Item3 } Using Classic Tuple as Method Parameter ...
Read MoreSwapping Characters of a String in C#
Swapping characters in a string involves replacing specific characters with their counterparts while preserving the original structure. In C#, this can be accomplished using various approaches including the Select method with LINQ, character arrays, or the Replace method. Syntax Following is the syntax for swapping characters using LINQ's Select method − string.Select(character => condition ? replacement : character).ToArray() Following is the syntax for swapping using character arrays − char[] charArray = string.ToCharArray(); // modify charArray elements new string(charArray) Using LINQ Select Method The Select method processes each character individually ...
Read MoreC# program to replace n-th character from a given index in a string
In C#, you can replace a character at a specific index in a string by converting the string to a character array, modifying the desired character, and then creating a new string from the modified array. Syntax Following is the basic syntax for replacing a character at a specific index − char[] charArray = originalString.ToCharArray(); charArray[index] = newCharacter; string newString = new string(charArray); Using ToCharArray() Method The most straightforward approach is to convert the string to a character array, replace the character at the desired index, and construct a new string − ...
Read MoreC# program to determine if any two integers in array sum to given integer
In this article, we'll learn how to determine if any two integers in an array sum to a given target integer. This is a common programming problem that can be solved using different approaches with varying time complexities. Problem Statement Given an array of integers and a target sum, we need to find if there exist any two numbers in the array that add up to the target value. Using Nested Loops (Brute Force Approach) The simplest approach is to check every possible pair of numbers using nested loops − using System; public ...
Read MoreMonth ("M", "m") Format Specifier in C#
The Month ("M", "m") format specifier in C# represents a custom date and time format string that displays the month and day portions of a date. This format specifier is defined by the current DateTimeFormatInfo.MonthDayPattern property and typically follows the pattern MMMM dd. Syntax Following is the syntax for using the Month format specifier − dateTime.ToString("M") dateTime.ToString("m") The custom format string pattern is − MMMM dd Using Month Format Specifier Basic Example using System; using System.Globalization; class Demo { static void Main() ...
Read MoreHow to use C# BinaryReader class?
The BinaryReader class in C# is used to read binary data from a stream in a specific encoding. It provides methods to read various data types like integers, doubles, strings, and byte arrays from binary files or streams. The BinaryReader class is located in the System.IO namespace and is commonly used for reading binary files, network streams, or any binary data format. Syntax Following is the syntax for creating a BinaryReader instance − BinaryReader reader = new BinaryReader(stream); Following is the syntax for reading different data types − int value = ...
Read MoreWho's Who in the Internet Standards World
Internet Standards refer to all the documented requirements both in technology as well as methodology pertaining to the Internet. The standardization process has maturity levels that ensure protocols are thoroughly tested before widespread adoption. Internet Standards Maturity Levels Proposed Standard − Standards that are ready for implementation but can be revised according to deployment circumstances. Internet Standard − Technically matured standards that define protocols and message formats. These include fundamental standards that form the Internet Protocol (IP). Internet Standards Organizations IETF Standards ...
Read More