Tuesday, July 2, 2013

Built-in Data Types

Built-in Data Types

Data Types are very important in C# language before storing a value in the variable/memory it needs to be specified a type. click on every Data Type to see example.
Data Type Range
byte 0 to 255
sbyte -128 to 127
short -32,768 to 32,767
ushort 0 to 65,535
int -2,147,483,648 to 2,147,483,647
uint 0 to 4,294,967,295
long -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
ulong 0 to 18,446,744,073,709,551,615
float -3.402823e38 to 3.402823e38
double -1.79769313486232e308 to 1.79769313486232e308
decimal -79228162514264337593543950335 to 79228162514264337593543950335
char A Unicode character.
string A string of Unicode characters.
bool True or False.
object An object.
        

byte(0 to 255)

byte x = 200; //Ok byte y = 256;//Error: Constant value '256' cannot be converted to a 'byte' byte x = 10, y = 20; byte z = x + y; //Error: Cannot implicitly convert type 'int' to 'byte'. An explicit conversion exists (are you missing a cast?)
 

sbyte(-128 to 127)

sbyte num = 255;//Error: Constant value '255' cannot be converted to a 'sbyte' Solution: sbyte can store -128 to 127 //You can save sbyte value in integer value directly as shown below sbyte num = 127; int tes = num;
        

short(-32,768 to 32,767)

short num = 32768;//Error: Constant value '32768' cannot be converted to a 'short' Solution: short can store -32,768 to 32,767 //You can save sbyte value in integer value directly as shown below short x = 32767, y = 32767; int tes = x + y; short z = tes;//Error: Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists (are you missing a cast?) short z = (short)tes;//65534 converting into short OutPut: -2 This is going cycling order.... no stop i mean positive values to negative values keep going :).
        

ushort(0 to 65,535)

ushort is Unsinged 16-bit integer ushort num = 65535;//this is good ushort num = 65536;//Error: Constant value '65536' cannot be converted to a 'ushort' Solution: ushort limits are 0 to 65,535 ushort x = 5, y = 6; ushort z = x + y;//Error: Cannot implicitly convert type 'int' to 'ushort'. An explicit conversion exists (are you missing a cast?) Solution: Addition of two ushort values will funtion with int data type so we have compile error. ushort z = (ushort)(x + y);//OK

INT (-2,147,483,648 to 2,147,483,647)

The int keyword denotes an integral type int i = 100; //Declare and initialize a variable of the type long vallong = 22; int i = vallong;//Cannot implicitly convert type 'long' to 'int'. An explicit conversion exists (are you missing a cast?) int i = (int)vallong; //Good
        

Unit(0 to 4,294,967,295)

Unit num = 123;//Ok long vallong = 123; Unit num = vallong;//Cannot implicitly convert type 'long' to 'System.Web.UI.WebControls.Unit'. Unit num = (Unit)vallong;//Ok
        

long(–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807)

long is a integeral type variable is nothing but Signed 64-bit integer. long num = 4294967296;//Ok int i = 123; long j = i; //Ok
        

ulong(0 to 18,446,744,073,709,551,615)

ulong will accept Unsigned 64-bit integer values. ulong num = 9827876347898279057; unsigned value can be long or ulong but it varies depends on the value size. long vallong = 9827876347898279057; //Cannot implicitly convert type 'ulong' to 'long'. The above value is too big to be stored in long data type and use ulong to store this type of big values. ulong num = 100.0;//Error: Cannot implicitly convert type 'double' to 'ulong'. ulong num = (ulong)100.0; //Ok
        

float (-3.402823e38 to 3.402823e38)

The float keyword signifies a simple type that stores 32-bit floating-point values. Usaually the right side operator is treated as double. So specify f or F to initialize float variable as shown below float num = 1.2f; A floating-point expression can contain the following sets of values: •Positive and negative zero •Positive and negative infinity •Not-a-Number value (NaN) •The finite set of nonzero values
        

double(-1.79769313486232e308 to 1.79769313486232e308)

double is value with 15-16 digits it stores more value than float initialize the double as shown below double num = 3.0; A floating-point expression can contain the following sets of values: •Positive and negative zero. •Positive and negative infinity. •Not-a-Number value (NaN). •The finite set of nonzero values.
        

decimal(-79228162514264337593543950335 to 79228162514264337593543950335)

The decimal keyword denotes a 128-bit data type. Compared to floating-point types, the decimal type has a greater precision and a smaller range, which makes it suitable for financial and monetary calculations. The approximate range and precision for the decimal type are shown in the following table. decimal num = 100.3m;//If you want a numeric real literal to be treated as decimal, use the suffix m or M decimal num = 3.5;//Literal of type double cannot be implicitly converted to type 'decimal'; use an 'M' suffix to create a literal of this type decimal num = 3.5m;//Ok
        

char(A Unicode character.)

The char keyword is used to declare an instance of the System.Char structure that the .NET Framework uses to represent a Unicode character. The value of a Char object is a 16-bit numeric (ordinal) value. char x = 'A'; char y = 'ABC';//Error: Too many characters in character literal char x = 100;//Error: Constant value '100' cannot be converted to a 'char' char x = (char)100;//Ok but Output will be d
        

string(A string of Unicode characters.)

The string type represents a sequence of zero or more Unicode characters. string is an alias for String in the .NET Framework. string a = "hello"; string b = "h"; // Append to contents of 'b' b += "ello"; Console.WriteLine(a == b); Console.WriteLine((object)a == (object)b); This displays "True" and then "False" because the content of the strings are equivalent, but a and b do not refer to the same string instance.
        bool(True or False.)
        The bool keyword is an alias of System.Boolean. It is used to declare variables to store the Boolean values, true and false.
        

object(An object.)

The object type is an alias for System.Object in the .NET Framework. You can assign values of any type to variables of type object. All data types, predefined and user-defined, inherit from the System.Object class. The object data type is the type to and from which objects are boxed.

Wednesday, June 26, 2013

The basic functionalities of 3 - Tier or N-Tier Architecture




Presentation Layer
  •  Gathering information from the user
  • Sending the user information to the business services from processing
  • Receiving the result of the business services processing
  • Presenting those results to the user

Business Layer

  • Receiving input from the presentation tier.
  • Interacting with the data services to perform the business operations.
  • Sending the processed results to the presentation tier.

Data Service Layer

  • Storage of data
  • Retrieval of data
  • Maintenance of data
  • Integrity of data

Tuesday, June 25, 2013

Display Div Tags side by side


If you are using div tags and they display vertically.
   
    <div>
        Test 1
    </div>
    <div>
        Test 2
    </div>
    <div>
        Test 3
    </div>


OutPut:




Sometimes you want them to display horizontally or side by side. Then use style 'float' as shown below.
    <div style="float: left">
        Test 1
    </div>
    <div style="float: left">
        Test 2
    </div>
    <div style="float: left">
        Test 3
    </div>


OutPut:

Wednesday, February 29, 2012

Asp.Net Page Life Cycle

Page request
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version of the page can be sent in response without running the page.

Start
In the start stage, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property.

Initialization
During page initialization, controls on the page are available and each control's UniqueID property is set. A master page and themes are also applied to the page if applicable. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.

Load
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state.

Postback event handling
If the request is a postback, control event handlers are called. After that, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page. (There is an exception to this sequence: the handler for the event that caused validation is called after validation.)

Rendering
Before rendering, view state is saved for the page and all controls. During the rendering stage, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream object of the page's Response property.

Unload
The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and cleanup is performed.


Source: MSDN

Tuesday, February 21, 2012

Using DotNetFactory in QTP

DotNetFactory enables QTP scripting to directly access methods and properties of a .Net object by creating an instance of this object. This object enables to work on user created forms, controls and other .Net objects.

To use DotNetFactory, you will first need to create the object instance using 'Create Instance' method.