How to Read Text Files Using C#

Hello, in this post I will show you how to read text files line-by-line using C#.

Setting Up and Running the Code

Let's say that you have a text file named "test.txt" with the following contents:

I am a simple
text file with
three lines.

We can read the contents of the file using the following code. Note that I am using a console application.

Using Methods With Value and Reference Types

In this post I will show you the practical usage of methods with value types and reference types in C#. I have used a console application to run the code I posted here. It might be helpful if you can also create your own console application so you can try the code samples yourself.

Value and Reference Types in C#

Here is the list of all value types in C#:

  • Structs (ex: System.DateTime)
  • Enums (ex: System.Data.CommandType)
  • Integral types (char, sbyte, byte, short, ushort, int, uint, long, ulong)
  • Float
  • Decimal
  • Double
  • Bool

ASP.NET MVC and QueryString

In this post I will show you how to post and access query string values using ASP.NET MVC 3.

Short Introduction to QueryStrings

A query string is a string that is appended to the end of a URL that follows a specific format.

Using JQuery AJAX GET with ASP.NET MVC JsonResult

Hi, in this post I will show how the client can communicate with the server using AJAX. Specifically, the client will be using the JQuery library, the server will be running on ASP.NET MVC, and the HTTP Method will be GET.

First off, create an MVC project in Visual Studio. I haven't tested MVC 2, but either MVC 3 or MVC 4 should work.

Improving Stringbuilder Performance

In one of our projects we had a requirement to produce a .csv file. In the solution I implemented, I used the StringBuilder class to create the contents of the csv.

It worked great, however it took more than one minute to create the file. What was wrong?