Browse by Tags

All Tags » How To (RSS)

Converting double to integer using cast and convert statement by vik20000in

Check out the code below. double d = 13.6; int i1 = Convert.ToInt32(d); int i2 = (int)d; if (i1 == i2) { Console.WriteLine("Equal"); } else { Console.WriteLine("Not Equal"); } The output of the above program would be “Not Equal”. The reasons being different...
Filed under: ,

Bankers Rounding in Math.Round Method by vik20000in

What would be the output of the following program? Console.Write(Math.Round(-0.5).ToString() + “~”); Console.Write(Math.Round(0.5).ToString()+ “~”); Console.Write(Math.Round(1.5).ToString()+ “~”); Console.Write(Math.Round(2.5).ToString()+ “~”); If you...
Filed under: , ,

LINQ and Aggregate function by vik20000in

LINQ also provides with itself important aggregate function. Aggregate function are function that are applied over a sequence like and return only one value like Average, count, sum, Maximum etc… Below are some of the Aggregate functions provided with...
Filed under: , , ,

Working with Joins in LINQ by vik20000in

While working with data most of the time we have to work with relation between different lists of data. Many a times we want to fetch data from both the list at once. This requires us to make different kind of joins between the lists of data. LINQ support...
Filed under: , , ,

Using the StopWatch class to calculate the execution time of a block of code by vik20000in

Many of the times while doing the performance tuning of some, class, webpage, component, control etc. we first measure the current time taken in the execution of that code. This helps in understanding the location in code which is actually causing the...

LINQ and the use of Repeat and Range operator by vik20000in

LINQ is also very useful when it comes to generation of range or repetition of data. We can generate a range of data with the help of the range method. var numbers = from n in Enumerable.Range(100, 50) select new {Number = n, OddEven = n % 2 == 1 ? "odd...
Filed under: , , ,

Retrieving only the first record or record at a certain index in LINQ by vik20000in

While working with data it’s not always required that we fetch all the records. Many a times we only need to fetch the first record, or some records in some index, in the record set. With LINQ we can get the desired record very easily with the help of...
Filed under: , , ,

LINQ and conversion operators by vik20000in

LINQ has a habit of returning things as IEnumerable. But we have all been working with so many other format of lists like array ilist, dictionary etc that most of the time after having the result set we want to get them converted to one of our known format...
Filed under: , , ,

Using set operation in LINQ by vik20000in

There are many set operation that are required to be performed while working with any kind of data. This can be done very easily with the help of LINQ methods available for this functionality. Below are some of the examples of the set operation with LINQ...
Filed under: , , ,

Grouping data in LINQ with the help of group keyword by vik20000in

While working with any kind of advanced query grouping is a very important factor. Grouping helps in executing special function like sum, max average etc to be performed on certain groups of data inside the date result set. Grouping is done with the help...
Filed under: , , ,
More Posts Next page »