Tuple, a new data structure in C#

Tuple is an interesting data structure in C#. It contains number and sequence. You can create tuple of 1 to 7 elements. Additionally you can create tuple of eight element using the TRest element. TRest element allows you to add nested tuple.

Let see example of basic tuple. We have student entity having marks fro seven subject. We can define this data structure by using tuple.

var tupleStudent = Tuple.Create("Mandar Badve", 87, 45, 76, 78, 64, 71, 80);
Console.WriteLine(""+ tupleStudent.Item1 + " got " + tupleStudent.Item2 + " marks in first subject.");
//// OUTPUT: Mandar Badve got 87 marks in first subject.
Console.WriteLine(""+ tupleStudent.Item1 + " got " + tupleStudent.Rest.Item1 + " marks in seventh subject.");
//// OUTPUT: Mandar Badve got 80 marks in seventh subject.

In above example first console will print the name of student accessed using Item1 of tuple and marks got in first subject accessed using Item2 of tuple. In second console we have access nested tuple using Rest property of tuple.

You can create tuple by using two ways.

  • Using constructor
var tupleUsingConstructor = new Tuple<string, int, int, int, int, int, int>("Mandar Badve", 87, 45, 76, 78, 64, 71);
  • Using helper method Create()
var tupleByHelperMethod = Tuple.Create("Mandar Badve", 87, 45, 76, 78, 64, 71, 80);

Create method have different overloads as follows:

Create<T1>(T1) Creates a 1-tuple, or singleton
Create<T1, T2>(T1, T2) Creates a 2-tuple, or pair.
Create<T1, T2, T3>(T1, T2, T3) Creates a 3-tuple, or triple.
Create<T1, T2, T3, T4>(T1, T2, T3, T4) Creates a 4-tuple, or quadruple.
Create<T1, T2, T3, T4, T5>(T1, T2, T3, T4, T5) Creates a 5-tuple, or quintuple.
Create<T1, T2, T3, T4, T5, T6>(T1, T2, T3, T4, T5, T6) Creates a 6-tuple, or sextuple.
Create<T1, T2, T3, T4, T5, T6, T7>(T1, T2, T3, T4, T5, T6, T7) Creates a 7-tuple, or septuple.
Create<T1, T2, T3, T4, T5, T6, T7, T8>(T1, T2, T3, T4, T5, T6, T7, T8) Creates a 8-tuple, or octuple.

app_offline.htm, make your application offline in minute

Some time you need to change/update database or update back end services or just shut down the application. During this activity you need to make your application offline. So, no user can access your web application during this activity.

app_offline.htm file make your work easier. This is very quick solution to make your application offline.

Create html file named app_offline.htm and write some custom message into the file just like ‘Application is down due to maintenance’. Place this file in the root directory of your application. As soon as you place file, application will be made offline to users and will show content of the app_offline.htm file for all the requests. Also the application will shut down and application domain will be unload from the server.

Existing request to the application will continue as it is. Only new request to the application  will get the content of the app_offline.htm file.

If you have added the reference of the JavaScript and the style sheets to your app_offline.htm file, this will not work. The request to these files will not be processed. So make your scripts and style inline. For the image you can use base 64 data of the image. Here you will find the various tool to convert image to base 64 from Google search.