Nizamuddin Siddiqui has Published 2303 Articles

How to Copy the entire contents of a directory in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Aug-2020 11:28:54

2K+ Views

While copying the entire contents of directory, it is more important that we have copy its sub directories and the related files.ExampleLet us consider demo source directory having sub directories and files like below. Below is the demo target directory which is empty initially.using System; using System.IO; namespace DemoApplication {   ... Read More

How to replace line breaks in a string in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Aug-2020 11:21:11

2K+ Views

Let us take we have to eliminate the line breaks, space and tab space from the below string.eliminate.jpgExampleWe can make use of Replace() extension method of string to do it. Live Demousing System; namespace DemoApplication {    class Program {       static void Main(string[] args) {       ... Read More

How can we update the values of a collection using LINQ in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Aug-2020 11:19:03

13K+ Views

If the collection is a List, then we can make use of ForEach extension method which is available as part of LINQ.Example Live Demousing System; using System.Collections.Generic; namespace DemoApplication {    class Program {       static void Main(string[] args) {          List fruits = new List ... Read More

What is the main difference between int.Parse() and Convert.ToInt32 in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Aug-2020 11:14:17

6K+ Views

Convert a string representation of number to an integer, using the int.Parse or Convert.ToInt32 method in C#. If the string cannot be converted, then the int.Parse or Convert.ToInt32 method returns an exceptionConvert.ToInt32 allows null value, it doesn't throw any errors Int.parse does not allow null value, and it throws an ... Read More

How to delete all files and folders from a path in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Aug-2020 11:12:07

4K+ Views

For deleting all the folders and its respective directories we can make us System.IO namespace available in C#. The DirectoryInfo() class provides the details of all sub directories and file in a directory.ExampleLet us consider a directory Demo having two sub directories and has some files like below.using System.IO; namespace ... Read More

How to fetch a property value dynamically in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Aug-2020 11:08:45

7K+ Views

We can make use of Reflection to fetch a property value dynamically.Reflection provides objects (of type Type) that describe assemblies, modules and types. We can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object ... Read More

How to convert byte array to string in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Aug-2020 11:05:15

19K+ Views

In .Net, every string has a character set and encoding. A character encoding tells the computer how to interpret raw zeroes and ones into real characters. It usually does this by pairing numbers with characters. Actually, it is the process of transforming a set of Unicode characters into a sequence ... Read More

Why the error Collection was modified; enumeration operation may not execute occurs and how to handle it in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Aug-2020 11:02:45

20K+ Views

This error occurs when a looping process is being running on a collection (Ex: List) and the collection is modified (data added or removed) during the runtime.Example Live Demousing System; using System.Collections.Generic; namespace DemoApplication {    public class Program {       static void Main(string[] args) {       ... Read More

How to create a comma separated string from a list of string in C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Aug-2020 10:56:42

13K+ Views

A List of string can be converted to a comma separated string using built in string.Join extension method.string.Join(", " , list);This type of conversion is really useful when we collect a list of data (Ex: checkbox selected data) from the user and convert the same to a comma separated string ... Read More

How to verify an exception that has been thrown in unit testing C#?

Nizamuddin Siddiqui

Nizamuddin Siddiqui

Updated on 08-Aug-2020 09:07:06

4K+ Views

There are two ways that we can verify an exception in unit testing.Using Assert.ThrowsExceptionUsing ExpectedException Attribute.ExampleLet us consider a StringAppend method which throws an exception needs to be tested.using System; namespace DemoApplication {    public class Program {       static void Main(string[] args) {       } ... Read More

Advertisements