Friday, June 29, 2012

FrameWork Runtime

.Net framework runtime is a protective bubble that wraps around your application.It prevents you from worrying about allocating and deallocating of memory for your variables.In some cases it protects the end user machine from unauthorized access of external resources.It basically is a protective layer that provides some benefits to the developer and end user.

when you write a c# code,in order for that code to be executed,it has to be compiled first.That process is called compilation in which it converts human readable code to machine readable code.The end result of compilation is a file called assembly . There is two types of assembly files . They are
1 .exe files
2 .dll files

.exe files - means executable assemblies. You can find it in the windows explorer.
.dll files - stands for dynamic link library.Basicaly it is a library of code shared by applications .

Debug assembly VS Release Assembly

when you are debugging, a debug version of assembly has been added to the debug folder in your project. And release version of assembly is created in the release folder. If you want to give your application to some body else,at the minimum we have to give the release version of the assembly and they also wanted to have the .net framework runtime.

Two phases of compilation
1. Parsing and compiling into Common Intermediate Language(CIL)- It goes through your code and make sure you didnt made any obvious mistakes, that is , certain kinds of errors that makes compilation to stop .
Once that is done the compiler converts the c# code into CIL code.This allows you to write an application in C# or java or vb.net or any other language ,they all get compiled into CIL.
After that Compiler adds the bootstrap code calling the .NET runtime.

2.Just In Time Compilation - In computing, just-in-time compilation (JIT), also known as dynamic translation, is a method to improve the runtime performance of computer programs..Net handles the hardware configuration and operating systems. The .net runtime evaluates the computers OS and the hardware and it creates the optimised version of the assembly that is specific to that configuration and it saves the application in a cache. This optimised version saved in cache is used in the future.

Integrated Development Environment(IDE) States
1.Design time - writing code time.
2.compile time- when you decide the compile or debug the application to create the debug or release version of the assembly.
3.Run time- Application running time or executing time.At this time unexpected errors pops up.They are called exceptions.
4.Debug time- this is a mix between design time and runtime.

Tuesday, January 17, 2012

Iteration Statements

You can create loops by using the iteration statements. Iteration statements cause embedded statements to be executed a number of times, subject to the loop-termination criteria. These statements are executed in order, except when a jump statement is encountered.

The following keywords are used in iteration statements:
-do
-for
-foreach
-in
-while

For Iterations
The for loop executes a statement or a block of statements repeatedly until a specified expression evaluates to false.

eg:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace forloop
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine(i);

}
Console.ReadLine();
}
}
}

Output :
0
1
2
3
4
5
6
7
8
9

You can break out of the loop by using the break keyword, or step to the next iteration in the loop by using the continue keyword.
You also can exit the loop by using a goto, return, or throw statement.

Foreach,in statements
The foreach statement repeats a group of embedded statements for each element in an array or an object collection that implements the System.Collections.IEnumerable or System.Collections.Generic.IEnumerable(Of T) interface.

eg:
class ForEachTest
{
static void Main(string[] args)
{
int[] fibarray = new int[] { 0, 1, 1, 2, 3, 5, 8, 13 };
foreach (int i in fibarray)
{
System.Console.WriteLine(i);
}
}
}
/*
Output:
0
1
1
2
3
5
8
13
*/

While statement
The while statement executes a statement or a block of statements until a specified expression evaluates to false.

eg:
class WhileTest
{
static void Main()
{
int n = 1;
while (n < 6)
{
Console.WriteLine("Current value of n is {0}", n);
n++;
}
console.ReadLine();
}
}

Output:
Current value of n is 1
Current value of n is 2
Current value of n is 3
Current value of n is 4
Current value of n is 5


do statement
The do statement executes a statement or a block of statements repeatedly until a specified expression evaluates to false. The body of the loop must be enclosed in braces, {}, unless it consists of a single statement. In that case, the braces are optional.

eg:
namespace dowhile
{
class Program
{
static void Main(string[] args)
{
int x = 0;
do
{

Console.WriteLine(x);
x++;
}
while (x < 5);
Console.ReadLine();
}
}
}
Output
0
1
2
3
4

Saturday, January 14, 2012

Operators ,Expressions and Statements

Operators ,Expressions and Statements

==> Statements - are complete sentences in C#
==> Statements are made up of one or more expressions .
==>Expressions contains operators and operands.

eg 1. Console.writeline("Type some numbers");

In the above example,
1. Console.writeline("Type some "numbers"); -whole thing is called expression.
2. Console and "type some numbers" are operands .

eg 2. a= b+5;
==> here "b+5" is the expression.
==> b is the operand and "+" is the operator.

eg 3. if(a==3)
==> if(a==3)- the whole thing is statement.
==> (a=3)is the expression

eg 4. myString = "john" + myLastName
==> "john" + myLastName is the expression .
==> john and myLastName are the operands and + is the operator.


Operands - can be objects , variables, or literal strings.
Operator - can be addition (+),concatenation (+), assignment (=), equality(==).

==>The operator for method invocation is (). This is what we use to pass our arguments to the parameters of the given method .
eg: Console.WriteLine(" hai "); and Console.ReadLine();

==> Dot operator(.) - which is for member access,that is , to access a method which is a member of a class .
eg: Console.WriteLine("hai"); -here writeline is the method and console is a class.

==>Declaration Statement
eg: int x;

==> Declaration Statement with initialization
eg: int x=3 ;

==> Expression statement
eg: myString = "john" + myLastName

==>Selection(Decision) Statement
eg: if(a>b)c = "myName"; - that if "a>b" then c is equal to "myName"

==>post-increment (x++),post-decrement (x--), pre-increment (++x) and pre-decrement (--x) operators
eg: suppose that int x= 0; then apply ++x,--x, x-- and x++

++x ==> 1 , --x ==> 0 , x-- ==> 0 and x++ ==> 1.

==>AND(&&) and OR(||) operators - These two are known as Logical Operators.
eg:1. if ( isTrue == false && isFalse == false )
{
// code block
}
You use the AND operator when you want to check more than one value at once. So in the example above, you're checking if both values are false. If and ONLY if both of your conditions are met ,then the code block get executed.

eg;2. if ( isTrue == false || isFalse == false )
{
// code block
}
If just one of our condition is false, then the code block will get executed.



Operators with their precedence and Associativity





Naming Conventions
A consistent naming pattern is one of the most important elements of predictability and discoverability in a managed class library. Widespread use and understanding of these naming guidelines should eliminate unclear code and make it easier for developers to understand shared code.

There are three types of capitalization styles defined:

1. Camel Case - The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized.
eg: myFirstName, numberOfDays etc.
Most programmers use this . Its a way to easily read something.

2. Pascal Case - The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized.
eg; DataType , DataSet etc.

3. Uppercase - all letters are capitalized.
eg; ADO, ID etc.

Friday, January 13, 2012

selection(conditional) statements

A selection statement causes the program control to be transferred to a specific flow based upon whether a certain condition is true or not.

The following keywords are used in selection statements:

if
else
switch
case
default

The if Statement
When the condition evaluates to a boolean true, a block of code for that true condition will execute.

It takes the following form:
if (expression)
statement1
[else
statement2]

where:

expression
An expression that can be implicitly converted to bool or a type that contains overloading of the true and false operators.
statement1
The embedded statement(s) to be executed if expression is true.
statement2
The embedded statement(s) to be executed if expression is false.

eg:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ifdecisionstmt
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please type your lucky number");
string number = Console.ReadLine();
if(number=="1")
{
Console.WriteLine("you have won a car");

}
else if(number=="2")
{
Console.WriteLine("you have won a boat");

}
else if(number=="3")
{
Console.WriteLine("you have won a van");

}
else
{
Console.WriteLine("sorry, try next time");

}

Console.ReadLine();
}
}
}

output
please type your lucky number
1
you have won a car

Switch Statement
The switch statement is a control statement that selects a switch section to execute from a list of candidates.

eg :
int caseSwitch = 1;
switch (caseSwitch)
{
case 1:
Console.WriteLine("Case 1");
break;
case 2:
Console.WriteLine("Case 2");
break;
default:
Console.WriteLine("Default case");
break;
}

Each case label specifies a constant value.Control is transferred to the switch section whose case label contains a constant value that matches the value of the switch expression, caseSwitch. If no case label contains a matching value, control is transferred to the default section.

==>no two case labels can contain the same constant value.

==>Execution of the statement list in the selected section begins with the first statement and proceeds through the statement list, typically until a jump statement
is reached, such as a break, goto case, return, or throw. At that point, control is transferred outside the switch statement or to another case label.

==>C# does not allow execution to continue from one switch section to the next.The following code causes an error.

switch (caseSwitch)
{
// The following switch section causes an error.
case 1:
Console.WriteLine("Case 1...");
// Add a break or other jump statement here.
case 2:
Console.WriteLine("... and/or Case 2");
break;
}

Inline conditional operator
Its a shortcut for writing a long code
eg;
string message = "";
if (x>y)
{
message = " car ;
]
else
{
message = "bus";
}

shortcut for this code is :
string message =(x>y)? "car" : "bus" ;

this is called in line conditional operators . Here we are trying to write code in few lines.

Variable Declaration

Variables are named "buckets" containing values in your computers memory .You can create buckets just the right size using dates and times,for strings,etc.

C# consist of the Boolean type and three numeric types - Integrals, Floating Point, Decimal, and Strings.
Integrals"- refers to the classification of types that include sbyte, byte, short, ushort, int, uint, long, ulong, and char.

Floating Point- refers to the float and double types.

String type - represents a string of characters.

Integral types

They are whole numbers, either signed or unsigned, and the char type(16 bits). The char type is a Unicode character

How to declare an integer

eg:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace declarevariable
{
class Program
{
static void Main(string[] args)
{
int x, y;
x = 6;
y = x + 4;
Console.WriteLine(y);
Console.ReadLine();
}
}
}
Output is 10.

Boolean Type
Boolean types are declared using the keyword, bool. They have two values: true or false.
eg: using System;

class Booleans
{
public static void Main()
{
bool white = true;
bool black = false;

Console.WriteLine("It is {0) that jasmine is white in color", white);
Console.WriteLine("The above statement is not {0}.", black);
}
}
output - It is true that jasmine is white in color
The above statement is not false.

Floating Point and Decimal Types

C# floating point type is either a float or double. They are used any time you need to represent a real number



The string Type - A string is a sequence of text characters.

C# Operators

C# provides a large set of operators, which are symbols that specify which operations to perform in an expression.



Left associativity means that operations are evaluated from left to right. Right associativity mean all operations occur from right to left, such as assignment operators where everything to the right is evaluated before the result is placed into the variable on the left.

Friday, January 6, 2012

Console application

Console applications means Word, Excel, notepad , etc. User typically interacts with a console application using only a keyboard and display screen.

First C# program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace helloworld
{
class Strong
{
static void Main(string[] args)
{
Console.WriteLine("hello world");
Console.ReadLine();

}
}
}
==>c# is case sensitive

==> whenever we create a project the IDE automatically add some common namespaces with the help of "using" statement .
that is, using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Namespace acts like a last name or surname to a class . that is to call this particular program we can use " hello world.strong" and thus it avoids confusion or ambiguity and organize classes.
Namespace will be whatever your project name is.
Namespace contains a group of code that can be called by c# programs.

==>static void main(string[] args)
In the case of a simple console application main() method is the first method to be executed. main function typically has access to the command arguments given to the program when it was executed.
main() is often called as "entry point". Every method must have a return type ,here it is void which means main() does not return a value.
Using static, main() can run on its own and it does not need an object for reference.

==> Every method also has a parameter list.

==> console.writeLine allows what we want to write in console window. console is a class in system namespace and writeLine is a method in console class. WriteLine also called as a method parameter because we are writing a string in ("") ,that is , (" hello world") for our console window.
ReadLine() accept no parameters.

==> classes and methods begin with "{" and ends with "}". Any statement within { } defines a block.

Friday, December 30, 2011

What is .Net ?

==> Runs Primarily on Microsoft Windows

==> Supports language interoperability , that is, each language can use the code which is written in other languages.

==> Programs written in .net runs in an environment called CLR(common language runtime). CLR provides security,memory management and exception handling.

==> Visual Studio is an IDE(Integrated development environment) developed by Microsoft for application development.

==> .Net framework is made of two major components , they are CLR(common language runtime) and FCL(framework class library).

The following diagram shows the .NET Framework




CLR abstracts the underlying operating system from your code, it means that your code has to run using the services provided by the CLR and we get a new name called managed code. The CLR provides its services to applications by providing a standard set of library classes that abstract all the tasks that you will ever need. These classes are called as the Base Class Libraries. On top of this, other development platforms and applications are built (like ASP.NET, ADO.NET and so on). Language compilers that need to generate code for the CLR must adhere to a common set of specifications as laid down by the Common Language Specification (CLS). Above this, you have all the popular .NET languages.