this blog contains information for .net and sql stuffs. You can find various tips and tricks to overcome problem you may be facing in ...

Monday, March 29, 2010

Typed V/S Un-Typed

In .Net framework, we many choice to use type safety and also we can use object without specifying its type before it will be used.

Typed means we know type, type can be anything int, string, float or any user defined type object etc.

Un-Typed as name suggest it does not mean absence of type, but uncertainty in types like we don’t have idea which type will come weather its int,float or something else.

In .Net Framework Object is base type of any types. So if we have declared variable as Object and going to assign value then we can assign any values string, int but we don’t know or have control to assign value to Object type variable.


Array list, dataset, and many collections are most popular example of un-typed; in array list we can store any value. Also in dataset we have one or many tables; even we don’t have idea which table will be stored in our dataset before we access dataset.

Due to above characteristic, it lacks of type checking, we should be take care when cast to any type.


Strongly typed dataset, Generics collection provides a great typed safety.

Strongly Typed Dataset we have dataset designed file, we can drag and drop tables, and we may have relation between them. Whenever we access typed dataset we can access tables and its column by its name we get intelligence menu.

We are sure that we are accessing particular table’s row and its column. We are also sure that value of column should be compatible with database’s type. Otherwise we would get compiler error.

With Generic collection, we can have collection of Dictionary,stringCollection and other collection which can accept only one type of data. Like if we are going to declare Dictionary to store key as integer and value as Person class object then we must follow it. If at the time of coding we do something wrong or use other object compiler will give error.


As per requirement we should use typed and untyped variable in our application. If we know that we are going to use only numeric datatype or have idea of particular type we should use typed, due to its checking of type safety at compile time, intelligence menu etc.

But if we don’t have any prior information of datatype, we don’t have other choice than un-typed. At the time of Un-Typed, care should be taken when casting to types. We should use try catch block to prevent crash of application.

No comments: