Article Tags
Looping techniques in C#

Looping techniques in C#

Loop statements allow us to execute a statement or a group of statements multiple times. The following are the loops supported by C# - Sr.No. Loop types and descriptions 1while loop When a given condition is true, it repeats a statement or a group of statements. It tests the condition before executing the loop body. 2for loop It executes a series of statements multiple times and abbreviates the code that manages the loop variables. 3do...while loop It is similar to the while statement, except that it tests the condition at the end of the loop body. Using C#, you can also use a foreach loop as shown below - example usingSystem;usingSystem.Collections;classDemo{ &n

Sep 23, 2023 pm 03:41 PM
C# OfType() method

C# OfType() method

Filter the collection based on each element type. Suppose you have the following list containing integer and string elements - list.Add("Katie"); list.Add(100); list.Add(200); Filter the collection and get only the elements of string type. varmyStr=fromainlist.OfType<string>()selecta; works the same way for integer types. varmyInt=fromainlist.OfType<int>()selecta;The following is the complete code-example real-time demonstration usingSystem;usi

Sep 23, 2023 pm 01:41 PM
How to truncate a file in C#?

How to truncate a file in C#?

To truncate a file in C#, use the FileStream.SetLength method. The following is the syntax - publicoverridevoidSetLength(longvalue); here, int64 = the length value of the stream

Sep 23, 2023 pm 12:21 PM
How to determine if a string contains all unique characters using C#?

How to determine if a string contains all unique characters using C#?

To determine if a string has unique characters, first check that the word in the string matches the next word - for(intj=i+1;j<val.Length;j++){ if(val[i]==val[j] )} If a match is found, it means that the string does not contain unique characters. If no match is found, the string contains all unique characters. If it matches, return false, that is, the unique character is not found -for(intj=i+1;j<val.Length;j++){ if(val[i]==val[j])&a

Sep 23, 2023 am 11:17 AM
C# program to add two time spans

C# program to add two time spans

First, set up two TimeSpans - TimeSpant1=TimeSpan.FromMinutes(1); TimeSpant2=TimeSpan.FromMinutes(2); To add it, use the Add() method - TimeSpanres=t1.Add(t2); Example UsingSystem; usingSystem. Linq;publicclassDemo{ publicstaticvoidMain(){ TimeS

Sep 23, 2023 am 10:05 AM
C# program to sort a list of string names using the LINQ OrderBy() method

C# program to sort a list of string names using the LINQ OrderBy() method

Sorting a list of string names is a common task in programming, and the LINQOrderBy() method in C# provides a simple and efficient way to perform this operation. In this article, we will walk you through a C# program to sort a list of string names using the LINQOrderBy() method. What is the LINQOrderBy() method? The LINQOrderBy() method is used to sort the elements in a sequence in ascending or descending order based on one or more keys. Keys can be simple properties or complex expressions that return a value based on one or more properties of the objects in the sequence. Syntax of OrderBy() method publicstaticIO

Sep 22, 2023 pm 11:57 PM
Main features of C# programming

Main features of C# programming

C# is a modern, general-purpose object-oriented programming language developed by Microsoft. C# is designed for use with the Common Language Infrastructure (CLI), which consists of executable code and a runtime environment that allows the use of a variety of high-level languages ​​on different computer platforms and architectures. Following are the main features of C#: Here is a list of few important features of C#: Boolean conditionals Automatic garbage collection Standard library Assembly version control Properties and event delegation and event management Easy to use generic indexer Conditional compilation Simple multi-threaded LINQ and Lambda expression integration with Windows

Sep 22, 2023 pm 11:33 PM
Print single and multiple variables in C#

Print single and multiple variables in C#

To display a single variable value in C#, just use Console.WriteLine() Let’s see an example. Here we are displaying the value of a single variable "a" in a single line - example usingSystem;usingSystem.Linq;classProgram{ staticvoidMain(){ inta=10; Console.WriteLine("Value:&qu

Sep 22, 2023 pm 09:57 PM
How to easily initialize a list of tuples in C#?

How to easily initialize a list of tuples in C#?

Tuples can be used when you want a data structure to hold an object with properties, but don't want to create a separate type for it. The Tuple class was introduced in .NET Framework 4.0. A tuple is a data structure that contains a sequence of elements of different data types. Tuple<int,string,string>person=newTuple<int,string,string>(1,"Test","Test1");A tuple can only contain up to eight elements. It gives compiler error when you try to include more than eight elements. list tuple var

Sep 22, 2023 pm 05:33 PM
C# program to check if a string contains special characters

C# program to check if a string contains special characters

To check if a string contains special characters you need to use the following method - Char.IsLetterOrDigit use it in a for loop and check if the string contains special characters. Suppose our string is - stringstr="Amit$#%"; Now convert the string to character array - str.ToCharArray(); Use for loop and check each character using isLetterOrDigit() method. Example Let's look at the complete code. Live demonstration usingSystem;namespaceDemo{ classmyA

Sep 22, 2023 pm 04:57 PM
C# program to sort a list of employees whose department is XYZ based on salary in descending order using LINQ

C# program to sort a list of employees whose department is XYZ based on salary in descending order using LINQ

In C#, LINQ (Language Integrated Query) is a powerful tool that allows you to sort, filter and manipulate data easily. In this article, we will demonstrate how to use LINQ to sort a list of employees in descending order based on their salary and job department. Sorting a list of employees based on salary in descending order and their department is set;}publicintSalary{get;set;}publicstringDe

Sep 22, 2023 pm 04:45 PM
How to find all unique quadruples close to zero using C#?

How to find all unique quadruples close to zero using C#?

The simplest way is that we can create four nested loops and check one by one whether the sum of all four elements is zero. If the sum of the four elements is zero, print the elements. Time complexity-O(n4)

Sep 22, 2023 pm 03:37 PM
Optional properties in C# classes

Optional properties in C# classes

An attribute is optional if it is possible and valid to be null. Properties of CLR types that are not null cannot be configured as optional. An example usage of optional attributes: Example [AttributeUsage(AttributeTargets.Property,Inherited=false,AllowMultiple=false)]internalsealedclassOptionalAttribute:Attribute{}publicclassEmployee{ publicstringEmpName

Sep 22, 2023 am 10:13 AM
Null pointer exception in C#

Null pointer exception in C#

NullReferenceExceptionisaC#versionofNullPointerException.TohandleandcatchitinC#,usetry-catch.Thebelowexampleshowsthatavariableissettonullandwhenwetrytoprintit,itthrowsanexceptionthatgetscaughtinthecatch−Try{  a=null;&n

Sep 21, 2023 pm 11:57 PM

Hot tools Tags

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

vc9-vc14 (32+64 bit) runtime library collection (link below)

vc9-vc14 (32+64 bit) runtime library collection (link below)

Download the collection of runtime libraries required for phpStudy installation

VC9 32-bit

VC9 32-bit

VC9 32-bit phpstudy integrated installation environment runtime library

PHP programmer toolbox full version

PHP programmer toolbox full version

Programmer Toolbox v1.0 PHP Integrated Environment

VC11 32-bit

VC11 32-bit

VC11 32-bit phpstudy integrated installation environment runtime library

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use