Getting Started With C-Sharp

Posted: February 23, 2010 in Programming

Hey finally i started with C# just learned about the variable types and some basic methodologies so sharing with you people and hoping that you learned something from it.

C# contains two types of variable.

Value Type:

Variable that are based on value types directly contain a values in a memory. Assigning one value type variable to another copies the contained value.
Further categories of value type:

Struct: A struct type is a value type that is typically used to encapsulate small groups of related variables, such as the coordinates of a rectangle.

Enumeration: An Enumeration is a distinct type consisting of a set of named constants called the enumerator list such as Days{mon , tues , wed , thu , Fri. , sat , sun}
Reference Type:
Variables of reference types, store references to the actual data.
example: arrays etc

Casting:

Converting between data types can be done using a cast; there are two types of casting Explicit casting and implicit casting.

Example :
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine(“..Hello World..”);

Console.WriteLine(“  “);

int i = 10;

float f = 0;

f = i;

Console.WriteLine(“The Value of f after implicit conversion will be”);

Console.WriteLine(f);

f = 10.5F;

i = (int)f;

Console.WriteLine(“The value of i after explixit conversion will be “);

Console.WriteLine(i);

Console.ReadLine();

}

}

}

Boxing & Unboxing:

Boxing is used to store value types in the garbage-collected heap.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int i = 123;

object a = i;

i = 456;

Console.WriteLine(“The value-type value = “);

Console.WriteLine(i);

Console.WriteLine(“The object-type value = “);

Console.WriteLine(a);

Console.Read();

}

}

}

Hope to get some good response ,till then Happy Blogging…!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s