Posts

Showing posts from 2010

Checking Overflow in C#

Image
When you use value type in your application for arithmetic operations, you will need to check the boundaries of data types after the operation completes every time i.e., have to ensure the value of data type does not exceeds the MaxValue of the data type, Overflow does not occur. Else you will get overflow Exception at runtime. Different languages treat this overflow in different Manner( C, C++ does not throw overflow exception rather wrap up the value, MS Visual Basic throws the Overflow Exception by default) Whereas   .Net does not check for the overflow exception until we explicitly we tell the CLR to check for Overflow Exception. By Default Overflow check is set off . Let's see an Example : {                      short val = 32767;        val =   (short)(val + 40000);  } In above code, we try to add constant valu...

C# Data types

Image
C# Primitive Data types : Any data types directly supported by the compiler are called primitive types. Primitive types map directly to types that exist in the base class library. These basic data types are used across programming language compilers regardless of managed code or unmanaged code, since it is essential to meet needs of storing the basic data(Numeric, character, Bool) in application development. Let us see Primitive Data types of C# : The CLR supports two different types    Value Type    Reference Type   Value Type : The variable representing the instance doesn’t contain a pointer to an instance; the variable contains the fields of the instance itself. Value type instances are usually allocated on a thread’s stack Value types are derived from System.ValueType 1. Value types holds the value itself and values are allocated in stack. 2. Being represented in two forms (boxing & ...

A zen Story

This is my first post in this blog, so i thought let me start with some good self motivational and inspiration zen stories before get into .net programming :-) you would have read many stories, but the following are most inspired me. Hope you also like it. Time To Learn ============= A young but earnest Zen student approached his teacher, and asked the Zen Master: "If I work very hard and diligent how long will it take for me to find Zen." The Master thought about this, then replied, "Ten years." The student then said, "But what if I work very, very hard and really apply myself to learn fast -- How long then ?" Replied the Master, "Well, twenty years." "But, if I really, really work at it. How long then ?" asked the student. "Thirty years," replied the Master. "But, I do not understand," said the disappointed student. "At each time that I say I will work harder, you say it will take me longer. Why do you say tha...