About the author

Vijay Kodali
E-mail me Send mail

Recent comments



The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2024

Convert time from one timezone to another timezone in Asp.Net

Handling timzone is quite simple in Asp.Net applications. First thing,   you should always store DateTime values in the DB in one timezone (UTC is most commonly used).  This eliminates many conversion issues.

Here is the sample code..

DateTime time1 = new DateTime(2008, 12, 11, 6, 0, 0);  // your DataTimeVariable 
TimeZoneInfo timeZone1 = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); 
TimeZoneInfo timeZone2 = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time"); 
DateTime newTime = TimeZoneInfo.ConvertTime(time1, timeZone1, timeZone2);

Get all available/supported Timezones in .Net TimeZoneInfo class

      foreach (var tz in TimeZoneInfo.GetSystemTimeZones())
                Response.Write(tz.DisplayName + " is Id =','" + tz.Id + "'");

Posted by Vijay on Wednesday, January 6, 2010 8:24 PM
Permalink | Comments (0) | Post RSSRSS comment feed

New features in C# 2.0

New features in C#  2.0

1)   Partial Types 

 Partial classes allow you to split a class definition across multiple source files. The benefit of this approach is that it hides details of the class definition so that derived classes can focus on more significant portions The Windows Form class is an example of a built-in partial class. In Visual Studio 2003 and earlier, forms classes included code generated by the form designer. Now that code is hidden in a partial class named form.Designer.vb or form.Designer.cs. When working on large projects, spreading a class over separate files allows multiple programmers to work on it simultaneously. When working with automatically generated source, code can be added to the class without having to recreate the source file. 

2)   Static Classes

Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class. Static class members can be used to separate data and behavior that is independent of any object identity: the data and functions do not change regardless of what happens to the object. Static classes can be used when there is no data or behavior in the class that depends on object identity. 

The main features of a static class are: 

§  They only contain static members.

§  They cannot be instantiated.

§  They are sealed.

§  They cannot contain Instance Constructors.   

3)   Generics

Generics are part of the .NET Framework's type system that allows you to define a type while leaving some details unspecified. Instead of specifying the types of parameters or member classes, you can allow code that uses your type to specify it. This allows consumer code to tailor your type to its own specific needs.

§    Use generic types to maximize code reuse, type safety, and performance.

§    The most common use of generics is to create collection classes.

§    The .NET Framework class library contains several new generic collection classes in the System.Collections.Generic namespace. These should be used whenever possible in place of classes such as ArrayList in the System.Collections namespace. 

4)    Nullable types and the null coalescing operator 

Nullable types are instances of Nullable structure. This Nullable structure is a generic struct type in base class library. It behaves like value type when it has a value which means that boxing or unboxing occurs. However when it does not have a value, it is null instead of the value types default value, and boxind or unboxing does not occur. 

C# provides language support for nullable types using a question mark as a suffix.

For example, int? is the same type as Nullable<int> 

One of the cool language features of C# is the ?? "null coalescing" operator.  This provides a nice way to check whether a value is null, and if so return an alternate value. 

5)   Yield:

One interesting new feature of the C# 2.0 is the "yield" keyword.  Basically it is used to iterate through objects returned by a method.Used in an iterator block to provide a value to the enumerator object or to signal the end of iteration The yield statement can only appear inside an iterator block, which might be used as a body of a method, operator, or accessor. The body of such methods, operators, or accessors is controlled by the following restrictions:

§    Unsafe blocks are not allowed.

§    Parameters to the method, operator, or accessor cannot be ref or out.

Categories: C# 2.0
Posted by vijay on Monday, June 4, 2007 2:04 PM
Permalink | Comments (0) | Post RSSRSS comment feed