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 6 of 75
C# Program to check whether a node is a LinkedList or not
The Contains() method in C# is used to check whether a specific value exists in a LinkedList. This method searches through all nodes in the LinkedList and returns a boolean value indicating whether the specified element is found. Syntax Following is the syntax for using the Contains() method − public bool Contains(T item) Parameters item − The value to locate in the LinkedList. Return Value Returns true if the item is found in the LinkedList; otherwise, false. LinkedList Contains() Method ...
Read Morec# Put spaces between words starting with capital letters
To place spaces between words starting with capital letters in C#, you can use LINQ to examine each character and insert spaces before uppercase letters. This technique is commonly used to format PascalCase strings into readable text. Syntax The basic syntax using LINQ to add spaces before capital letters − string.Concat(str.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' '); Using LINQ with Select and IsUpper The following example demonstrates how to add spaces before each uppercase letter in a PascalCase string − using System; using System.Linq; class Demo ...
Read MoreBuffer GetByte Example in C#
The Buffer.GetByte() method in C# allows you to read individual bytes from an array at a specified byte position. This method is useful when you need to examine the binary representation of data stored in arrays of primitive types. Syntax Following is the syntax for the Buffer.GetByte() method − public static byte GetByte(Array array, int index) Parameters array − The source array from which to read the byte. index − The zero-based byte position within the array. Return Value Returns a byte value at the specified position in the ...
Read MoreWhat are string literals in C#?
String literals in C# are constant string values enclosed in double quotes "" or prefixed with @"" for verbatim strings. A string literal contains characters that can include plain text, escape sequences, and Unicode characters. Types of String Literals C# supports several types of string literals − Regular String Literals: Enclosed in double quotes with escape sequences Verbatim String Literals: Prefixed with @ symbol, allowing multi-line strings and literal backslashes Raw String Literals: (C# 11+) Use triple quotes """ for complex strings Syntax Following are the different syntaxes for string literals − ...
Read MoreSort the words in lexicographical order in C#
Lexicographical order means sorting strings alphabetically, similar to how words are arranged in a dictionary. In C#, there are multiple ways to sort an array of strings in lexicographical order using built-in methods and LINQ. Syntax Using LINQ query syntax − var sorted = from word in array orderby word select word; Using Array.Sort() method − Array.Sort(array); Using LINQ OrderBy() method − ...
Read MoreHow to create an infinite loop in C#?
An infinite loop is a loop that never terminates and repeats indefinitely. While infinite loops are generally undesirable in most applications, they can be useful in specific scenarios like game loops, server applications, or continuous monitoring systems. There are several ways to create infinite loops in C#, each with different syntax and use cases. Using For Loop The most common way to create an infinite loop is by manipulating the loop condition so it never becomes false − using System; class Program { static void Main(string[] args) { ...
Read MoreValidate IP Address in C#
An IP Address is an Internet Protocol address that is a series of numbers assigned to each device on a computer network. In C#, the IPAddress class in the System.Net namespace provides methods to work with and validate IP addresses. There are several approaches to validate IP addresses in C#, including using the built-in IPAddress.TryParse() method and regular expressions for custom validation. Syntax Following is the syntax for using IPAddress.TryParse() method − bool IPAddress.TryParse(string ipString, out IPAddress address) Parameters ipString − A string that contains an IP address in dotted-decimal notation ...
Read MoreWhat are identifiers in C#?
An identifier is a name used to identify a class, variable, function, or any other user-defined item in C#. Identifiers are fundamental building blocks that allow developers to name and reference different elements in their code. Rules for Naming Identifiers The basic rules for naming identifiers in C# are as follows − A name must begin with a letter or underscore that could be followed by a sequence of letters, digits (0-9), or underscores. The first character in an identifier cannot be a digit. It must not contain any embedded space or special ...
Read MoreOptimization Tips for C# Code
C# code optimization involves writing efficient code that executes faster and uses memory more effectively. Here are essential optimization tips that can significantly improve your application's performance. Prefer Generic Collections Over Non-Generic Use List instead of ArrayList whenever possible. Generic collections provide type safety and better performance by avoiding boxing and unboxing operations − using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; class Program { public static void Main() { // Inefficient - ArrayList with boxing ArrayList arrayList = new ...
Read MoreHow to perform Merge Sort using C#?
Merge Sort is a sorting algorithm that uses the divide and conquer method. It divides the array into two halves, recursively sorts each half, and then merges them back together in sorted order. This process continues until the entire array is sorted. How Merge Sort Works Merge Sort follows these steps − Divide: Split the array into two halves at the middle point Conquer: Recursively sort both halves Merge: Combine the two sorted halves into a single sorted array Merge Sort Divide and Conquer ...
Read More