Tuesday, 6 September 2016

Did you know What is the base of C#?





Did you know What is the base of C#?
We all know What is C# but donot know basics concept in Csharp . In below section I have tried to explain you some basics of CSharp.

Using Blocks of Code
By enclosing the statements between opening and closing curly braces.Once the block has been created it became logically one unit

if(x>y)
{
  Console.WriteLine(“welcome to C#”);
}

   
Semicolons and Positioning
In C#, semicolons indicate end of statements. A block is set of logically connected statements that is surrounded by opening and closing statements.

x=y;
y=y+1;
Console.WriteLine(“X =”+x+” Y= “+y);

Datatype 

Byte(8) -> sbyte(8) -> char(8)-> short (16) -> ushort(16) -> int(32) -> uint(32) -> float(32) -> long(64) ->ulong(64) -> decimal(128)

C# uses a 16-bit character type called Unicode . Unicode defines a character set that is large enough to represent all of the characters found in human language.

Some More Options

When you want to print the out in C# we use WriteLine ().

Syntax:

WriteLine(“formatting string”,arg0,agr1,…… , argN);

 Formatting using WriteLine

Console.WriteLine(“Student has{0,10} or{1,5} marks”,90,95);

As you can see, spaces have been added to fill out unused portion of fields. Mininum field width is just that: Minimun width

Formatting on Float datatype

We can do this using #s to mark the digit positions.

Console.WriteLine(“Here is 10/3: 
{0:#.##},10.0/3/0);
OutPut is 10/3: 3.33

Literals : is refer to fixed values which are also known as constants. C# literals can be of any value datatype. Integer literals create an int, uint, long, ulong value by default they can still be assigned to variable of type byte,sbyte,short or ushort. C# also allows you to use scientific notation for floating point number. Floating point literal are type of double.

Hexadecimal Literal:
Base number 16 is called hexadecimal literal and which uses the digit 0 though 9 plus letter A through F, which stand 10,11,12,13,14 and 15.

Count=0xAF;

Character Escape Sequence:
C# provides several escape character which is also known as backlash Character constants. Eg \a,\b,\r,\n,\t etc..

String Literals:
A string us a set of characters enclosed in double quotes.

Console.WriteLine(“Welcome to world of C-Sharp”);

Variables:  which stores the data. Variables which are declared within method is known as Local variables.

Scope and Lifetime of Variable:
C# allows a local variable to be declared within block. A block is begun with an opening and closing curly brace .A block defines a declaration space or scope. Each time you start a new block you are creating a new scope. A scope determine what objects are visible to other parts it is also known as lifetime of those objects.

In C# most important scope are those defined by a class and those defined by a method. This is known as Class Variable scope.

C# scope rule may be surprise you that although block can be nested, no variable declared within an inner scope can have same name as available declared by an enclosing scope. So designers of C# felt that this name hiding could easily lead to programming errors and disallowed it.

Type Conversion and Casting

int i;
float f;
i=f;// covert float value into int



Automatic Conversion
In two case automatic conversion will occurs
1.       The two type are compatible
2.       The destination type is larger than source type

When two condition meet this is known as widening conversion.

Casting Incompatible types
A cast is an instruction to the compiler to convert one type to another.

Syntax:
(Target-type) expression


Example:
double d;
int i=(double)d;

I hope that the functionality of the above attribute is clear to you now. Now you can use this code in your application. If you have further question, just drop a line below and I will try to answer you as soon as possible.

Last but not least, connect with me on Twitter , Facebook , LinkedIn and Google+ for technical updates and articles news. We won’t spam or share your email address as we respect your privacy.


No comments:

Post a Comment