Server Side Programming Articles - Page 1551 of 2646

How to read a CSV file and store the values into an array in C#?

Nizamuddin Siddiqui
Updated on 25-Mar-2021 04:45:41

29K+ Views

A CSV file is a comma-separated file, that is used to store data in an organized way. It usually stores data in tabular form. Most of the business organizations store their data in CSV files.In C#, StreamReader class is used to deal with the files. It opens, reads and helps in performing other functions to different types of files. We can also perform different operations on a CSV file while using this class.OpenRead() method is used to open a CSV file and ReadLine() method is used to read its contents.OpenRead() method is used to open a CSV file and ReadLine() ... Read More

How to get the thread ID from a thread in C#?

Nizamuddin Siddiqui
Updated on 25-Sep-2020 11:07:15

4K+ Views

A thread is defined as the execution path of a program. Each thread defines a unique flow of control. If your application involves complicated and time-consuming operations, then it is often helpful to set different execution paths or threads, with each thread performing a particular job.Threads are lightweight processes. One common example of use of thread is implementation of concurrent programming by modern operating systems. Use of threads saves wastage of CPU cycle and increase efficiency of an application.In C#, the System.Threading.Thread class is used for working with threads. It allows creating and accessing individual threads in a multithreaded application. ... Read More

How to find the Number of CPU Cores in C#?

Nizamuddin Siddiqui
Updated on 25-Sep-2020 11:05:41

3K+ Views

There are several different pieces of information relating to processors that we can getNumber of physical processorsNumber of coresNumber of logical processorsThese can all be different; in the case of a machine with 2 dual-core hyper-threadingenabled processors, there are 2 physical processors, 4 cores, and 8 logical processors.The number of logical processors is available through the Environment class, but the other information is only available through WMI (and you may have to install some hotfixes or service packs to get it on some systems) −Add a reference in your project to System.Management.dll In .NET Core, this is available (for Windows ... Read More

How to calculate the total number of items defined in an enum in C#?

Nizamuddin Siddiqui
Updated on 25-Sep-2020 11:03:40

2K+ Views

An enum is a special "class" that represents a group of constants (unchangeable/readonly variables).To create an enum, use the enum keyword (instead of class or interface), and separate the enum items with a comma −By default, the first item of an enum has the value 0. The second has the value 1, and so on.To get the integer value from an item, you must explicitly convert the item to an intYou can also assign your own enum values, and the next items will update the number accordingly −Enums are often used in switch statements to check for corresponding values −Exampleclass ... Read More

How do I copy items from list to list without foreach in C#?

Nizamuddin Siddiqui
Updated on 25-Sep-2020 11:01:32

1K+ Views

The List is a collection of strongly typed objects that can be accessed by index and having methods for sorting, searching, and modifying list. It is the generic version of the ArrayList that comes under System.Collection.Generic namespace.List equivalent of the ArrayList, which implements IList.It comes under System.Collection.Generic namespace.Listcan contain elements of the specified type. It provides compile-time type checking and doesn't perform boxing-unboxing because it is generic.Elements can be added using the Add(), AddRange() methods or collection-initializer syntax.Elements can be accessed by passing an index e.g. myList[0]. Indexes start from zero. List performs faster and less error-prone than the ArrayList.A ... Read More

What is the AddSingleton vs AddScoped vs Add Transient C# Asp.net Core?

Nizamuddin Siddiqui
Updated on 25-Sep-2020 10:55:59

11K+ Views

There are three ways by which dependencies can be registered in Startup.cs. i.e. AddSingleton, AddScoped and AddTransient.Add SingletonWhen we register a type as singleton, only one instance is available throughout the application and for every request.It is similar to having a static object.The instance is created for the first request and the same is available throughout the application and for each subsequent requests.public void ConfigureServices(IServiceCollection services){    services.AddSingleton() }Add ScopedWhen we register a type as Scoped, one instance is available throughout the application per request. When a new request comes in, the new instance is created. Add scoped specifies that ... Read More

How to handle errors in middleware C# Asp.net Core?

Nizamuddin Siddiqui
Updated on 25-Sep-2020 10:54:36

2K+ Views

Create a new folder named CustomExceptionMiddleware and a class ExceptionMiddleware.cs inside it.The first thing we need to do is to register our IloggerManager service and RequestDelegate through the dependency injection.The _next parameter of RequestDeleagate type is a function delegate that can process our HTTP requests.After the registration process, we need to create the InvokeAsync() method. RequestDelegate can’t process requests without it.The _next delegate should process the request and the Get action from our controller should generate a successful response. But if a request is unsuccessful (and it is, because we are forcing exception), our middleware will trigger the catch block ... Read More

What is Metapackage in C# Asp.net Core?

Nizamuddin Siddiqui
Updated on 25-Sep-2020 10:52:07

4K+ Views

It is known that Microsoft.AspNetCore package is one of the packages added to many ASP.NET Core templates.The Microsoft.AspNetCore package is repeatedly included as one of the usual project dependencies when opening a new ASP.NET Core project. It delivers many of the crucial packages to position up a basic ASP.NET Core application.Though, this package does not contain any actual dlls or code itself, it merely contains a series of dependencies on additional packages. By adding this package to your project, you bring in all the relevant packages along with their dlls on which it depends and it is called a metapackage.Specifically, ... Read More

What is the purpose of Program.cs file in C# ASP.NET Core project?

Nizamuddin Siddiqui
Updated on 25-Sep-2020 10:50:45

1K+ Views

ASP.NET Core web application is actually a console project which starts executing from the entry point public static void Main() in Program class where we can create a host for the web application.public class Program{    public static void Main(string[] args){       BuildWebHost(args).Run();    }    public static IWebHost BuildWebHost(string[] args) =>    WebHost.CreateDefaultBuilder(args)    .UseStartup()    .Build(); }The WebHost is a static class which can be used for creating an instance of IWebHost and IWebHostBuilder with pre-configured defaults.The CreateDefaultBuilder() method creates a new instance of WebHostBuilder with pre-configured defaults. Internally, it configures Kestrel, IISIntegration and other configurations. ... Read More

What is the use of UseIISIntegration in C# Asp.net Core?

Nizamuddin Siddiqui
Updated on 25-Sep-2020 10:49:24

3K+ Views

All ASP.NET Core applications require a WebHost object that essentially serves as the application and web server. WebHostBuilder is used to configure and create the WebHost. You will normally see UseKestrel() and UseIISIntegration() in the WebHostBuilder setup code.What do these do?UseKestrel() − This registers the IServer interface for Kestrel as the server that will be used to host your application.In the future, there could be other options, including WebListener which will be Windows only.UseIISIntegration() − This tells ASP.NET that IIS will be working as a reverse proxy in front of Kestrel.This then specifies some settings around which port Kestrel should ... Read More

Advertisements