Sei sulla pagina 1di 32

Ui

Introduction

1. Microsoft .Net release by Microsoft corporation.


2. Java developed by sun micro system. Microsoft is big competitor to the sun micro
system. Sun Micro system is Group of the companies developed java. It is open source.
Difference between the Microsoft and Sun Micro system?
Sl.No
1
2
3

Microsoft Corporation
It is developed MS.Net
.Net is not a open source. We need
to pay money to use this software.
.net
having
rich
graphic
user
interface editor.

Versions History of the MS.Net:


VS2003
VS2005
Visual Studio
1.0 & 1.1
2.0
Framework

VS2008
3.0 & 3.5

Sun Micro system


It is developed Java
Java is open source.
Java not having the editors
except third party editors.

Vs2010
4.0

VS2012
4.5

MS.Net nothing but a collection of following languages:

Note: Each .net framework language having the facility to develop windows and Web applications

What is the Web Application:


Web application is a website (ASP, ASPX, PHP, html etc) and will always be viewed through web
browser.

What is the Windows Application:


Windows application is mostly an exe-file for example MS Word, Notepad and these applications
run "standalone".

Difference between the Windows and Web Applications?


Sl.No

Web

Win

Web application is a website


(ASP, ASPX, PHP) and will
always be viewed through web
browser.

Windows application is mostly an


exe-file for example MS Word,
Notepad and these applications
run "standalone".

IIS server required to run the


web application.

IIS server not required to run


the web application.

Before the MS.Net which technologies used for Windows and Web:
a) VB 6.0(Visual Basic) for windows Application
b) ASP 3.0(Active Server Pages) for web Application
Active Server Pages (ASP) 3.0:
It is a combination of Html+ JavaScript + VBScript.
HTML Used for web page development
JavaScript used for client-side validations. so we called JavaScript is Clint-side script.
VBScript is used for server-side Transactions. Mainly used data base transactions.

C#.Net Basic Concepts:


C#.Net is a fully object oriented language and component based language.
It is developed by combining the concepts of C,C++,Java and productivity of VB 6.0.
Difference between the C#.Net and Java?
C#.Net
Unlike java,C#.net data type are
objects
C#.Net support the struct keyword
In C#.Net parameters passed by
reference by using ref keyword

Java
Java Data types are not an objects
Java does not support.
In Java Parameters passed by values

In the C#.Net series of statements terminated with a semicolon.


Type of comments:
1) Single-Line comments
2) Multiline comments
Single-Line comments:
Single line comments begin with double backslash(//) symbol.
Ex: // this is Gsoft Technology
Multi-Line Comments:
Multiline comments used to comment the multiple statements. Multiline comments starts with /* and
ends with */
Example:
using System. Data;
/*using System;*/
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// this is C# concepts (this is single line comment)
Below is the multiline comment:
/* This is Gsoft
This is india
Gsoft Technologies
*/
}
}

Access Modifiers or Access specifies:


C#.Net Supports five types of access specifies or access modifiers.
1.Public
2.Private
3.Protected
4.Internal
5.Protechted internal
Example:

Public:
Public members have no access restriction. We can access public members by creating object, in
derived class and with in the assembly and in other assemblies also.(in another application). . It can
be accessed everywhere.

Field , Properties and Members declared with public keyword are accessible from anywhere in the
class and outside of the class also we can access.
Within the class - Visible
a)Visible the public members within the same Class
b) Visible the public members in other Class by creating the object
c)Visible public members in derived/inherited/child Class
4)Visible public members from other namespace(application) by creating the object.
5)Visible public members from other namespace(application) by inheritance.

Private:
The scope of the private members is limited.
They are not accessible outside the Class or structure , block or module .
We cannot access private members by creating object and also we cannot access private members in
derived class.

Private keyword allows a class to hide its member and variables from other class objects and
functions. So it is not visible outside the class.
When you do not specify any data member as public, protected, or private, then the default access
specifies for a data member is private.
a)Visible the private members within the same Class
b) We cannot visible the private members in other Class by creating the object.
c) We cannot visible private members in derived/inherited/Child Class.
d)We cannot visible private members from other application by creating the object.
e) We cannot visible private members from other application by inheritance.

Protected:
You cannot access protected members by creating object. You can access protected members only
in derived/inherited/child class.
The type or member can only be accessed by code in the same class or struct, or in a derived class.
a)Visible the protected members within the Same Class
b)We cannot visible the protected members in other Class by creating the object.
c)We can visible protected members in derived/inherited/Child Class.
c)We cannot visible protected members from other application by creating the object.
d)We can visible protected members from other application by the inheritance.

Note: Variable declared with protected keyword are accessible within the class and inherited
classes.
The protected access specified in C# allows a class to hide its variables and member from other
class objects except the child class. This
Field , Properties and Members declared with Protected keyword are accessible in the inherited
classes

Internal:
Internal members can be accessed from any class or method defined within the application but not
from another application.
If we do not specify any data member as public, protected, or private the default access specifier
for a class is internal.
a)Visible the internal members within the same Class
b)We can visible the internal members in other Class by creating the object.
c)We can visible internal members in derived/inherited/Child Class.
d)We cannot visible internal members from other application by creating the object
e)We cannot visible internal members from other application by inheritance.

Protected internal:
The scope of this pecifier is similar to the protected as well internal.
access the member within the class and from other application we able to get it through the
inheritance.
a)Visible the protected internal members within the same Class
b)Can visible the protected internal members in other Class by creating the object.
c)Can not visible protected internal members in derived/inherited/Child Class.
d)We cannot visible protected internal members from other application by creating the object.
d)We can visible protected internal members from other application by inheritance.
Destructors cannot have accessibility modifiers.

The type or member can be accessed by any code in the same assembly, or by any derived class in another
assembly

C#.Net Data Types:


Data types(type of data) that can be stored in variable.
Variables:
Variable is a small amount of memory which is used to store specified data type values.
Variables are storage area for data.
All the variable names are case-sensitive
All the local variable must be declared and initialized before using.
Note:
To extend the lifetime of a variable in vb.net we use the static keyword instead of Dim keyword.

There are two types of the data types:

Value Type: Value data type variables contain the data directly.
Value types are stored in the stock memory.
Reference Types:
The reference type used to store the address location of the data. reference of another memory
location that contain the data.

Difference between the Value type and Reference type?


SL.No
1
2
3
4

Value Type
Value types are stored on the
stack
A value type variable contain the
data directly.
Value types cannot be inherited

Pre-defined Value Types:

how to declare the data types:


'VB
Dim b As Boolean = False

// C#
bool b = false

Reference Type
Reference types stored on the managed
heap.
The reference type used to store the
address location of the data
reference types can inherited.

Predefined Value Types or Primitive Types:


1Int(4bypes)
2.long(8byptes)
3.byte(8bits)
4.sbyte(8bits)
5.Short
6.ushort
7.uint(4bits)
8.ulong(8 bytes)
9.float(4 bytes)
10.double(1byte)
11.bool(1 byte)
12.char(2 bytes)
13.(Decimal)
14.DateTime

What is the boxing and un-boxing?


Boxing is implicit conversion of value type into the reference type.
un-boxing is reverse process for boxing.
Un-Boxing:
To return the boxed object back to a value type ,We must explicitly un box it.
how to declare the data types:
protected void Page_Load(object sender, EventArgs e)
{
int i = 123;
object o = i;//boxing
int j = (int)o;//un boxing
}

Creates an integer i and implicitly boxes it when it assigned to the object o.


The value is then explicitly unboxed and assigned to a new int whose value is displayed.
Difference between the string and string builder:
System. String provides a set of members for working with text
String : At the time of concatenation each time it will re- allocate the new memory and previous memory
allocations also available to wastage of memory is remain.
in StringBulder:
It append the string with the same memory allocation.

Parameters:
Difference between the Ref and Out keywords:
Ref:
1. Ref is a keyword. It keyword used while passing and receiving the variables.
2.It allows to modify the original variable.

Difference between the Ref and Out Keywords?

Ref
Variable must be initialized
public class A
{
public int Fun(ref int x)
{
return 2 * x;
}
}
Calling:
A obj = new A();
int x;
x = 6;//Variable need to be initialized
obj.Fun(ref x);

Out
Initialization of the variable is
optional.
public class A
{
public void Fun(out int x)
{
x= 2 * 5;
}
}
Calling:
A obj = new A();
int x;//Variable initialization should be
optional.
obj.Fun(out x);

The ref variable should not be constant


The variable should not be assigned.

Out:
1.Out is a keyword. Initialization of the out variable optional.

Pre-defined User Types:


Enumerations:
Enumerations is a user-defined value type.
Enumerations provide powerful alternative to the constants or
An Enumeration is a group of related constants.
The enum keyword is used to declare an enumeration

set of named constants are called the enumerator list


An Enumeration begins with the keyword enum which is generally followed by an identifiers sugh
as
Enumerations are special sets of named values which all maps to a set of numbers,
usually integers.

Ex: Enum Temparature.


Example:
public class Default2 : System.Web.UI.Page
{
public enum Days { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday };
protected void Page_Load(object sender, EventArgs e)
{
Days day = Days.Monday;
Response.Write(day);
}
}

The enum declaration ends with the enumerator list. The enumerator list contains the constant
assignments for the enumeration, each separated by comma.

The enumeration begins at 0 and each subsequent value count up from the previous
Example:
public class Default2 : System.Web.UI.Page
{
int first, second, third, fourth;
public enum Count
{
first,
second,
third=20,
fourth
};
protected void Page_Load(object sender, EventArgs e)
{
Response. Write((int)Count.first);
Response. Write((int)Count.fourth);
}
}
Output:
0
21(the value of 3rd will be 20 and fourth will be 21).

The enumeration begins with 0 and each subsequence value count up from the previous so fourth
value is 21
Note: the enumerator cannot declare inside the procedure. it can declare at class or module.

Constants:

The variables whose values do not change during the execution of a program are known as constants
ex: const int rows =10;

Difference between the Read only and Constant?


The read-only and constants are same they can never be modified but
Read-only
Read-only allows to initializing
variables at run-time.
public readonly DateTime dt =
DateTime.Now;

Constant
Constant must be initialized at compile time.
public const int x=2;

Pre-defined Reference Types:


string
object
User-defined Reference Types:
Class:
Class is collection of fields, properties, methods and events
class keyword used to define the class.
syntax:
class A
{
}
Arrays:
Array is a collection of objects with similar types.
In C#.Net arrays are objects.
Name space is : system. array.
Arrays have same name with different index no which starts from zero.
square brackets [ ] are used to declare an array.
ex: a[ ]
dis-advantages:

1.size is fixed
2.Allows only similar type of data.

Types of the arrays:


a

Single dimensional

Multi dimensional arrays

Jagged arrays

Single-Dimension arrays:
Array have only in on dimension
Declaration of single dimension array:
int[] x = new int[5];
int[] x1 = new int[] { 1, 2, 3, 4, 5, 6 };
int[] x2 = { 1, 2, 3, 4, 5 };
string[] WeekDays = new string[] {"Sun","Mon","Tues","Wed","Thu","Fri","Sat" };

Example:

protected void Button1_Click(object sender, EventArgs e)


{
int[] x = { 1, 2, 3, 4, 5 };
for(int i=0;i<x.Length;i++)
{
Response. Write(x[i]);
}
}

Output:
1,2,3,4,5

Multi-Dimension arrays:
Arrays can have more than one dimensions.
Declaration of Multi dimension array:

int[,] x = new int[4,2]; //Two Dimensional array


int[,,] x1 = new int[4, 2, 3]; //Three Dimensional array
int[,] x2 = {{1, 2},{3, 4},{5,6},{7,8 }};
1,2
3,4
This array has 4 rows and 2 columns
5,6
7,8

Example:
protected void Button1_Click(object sender, EventArgs e)
{
int[,] x = new int[,] {{1, 2},{3, 4},{5,6},{7,8} };
for(int i=0;i<3;i++) //0 to 3 is no of rows=4
{
for (int j = 0; j < 1; j++) //0 to 1 is no of columns=2
{
Response.Write(x[i,j]);
}
}

Output:
1,2,3,4,5

Jagged-Dimension arrays:
jagged array is an array whose elements are arrays.
Jagged array is sometimes called an array-of-arrays and also called dynamic arrays.
It is called jagged because each of the rows need not be the same size as all the others and thus a
graphical representation of the array would not be square.
Declaration of single dimension of Jagged array with 3 elements:
int[][] MyJaggedArray = new int[3][];
int[][] MyJaggedArray1 = new int[][] { new int[] { 1, 2, 3, 4, 5 }, new int[] { 1, 2, 3, 4},
new int[] { 1, 2}
};
int[][] MyJaggedArray2 = {
new int[] { 1, 2, 3, 4, 5 },
new int[] { 1, 2, 3, 4},
new int[] { 1, 2}
};

Each of element which is single-dimensional array of integer.


Before we can use jagged arrays it's elements mush be initialized.
MyJaggedArray[0] = new int[5];
MyJaggedArray[1] = new int[4];
MyJaggedArray[2] = new int[2];

Array Conversion:
Array conversion two types:

1.Implicit conversion(elements can be implicitly converted)


2.Explicit conversion(elements can be explicitly converted0
Note: The conversion possible between arrays if their dimensions are equal.
Parameterized arrays(Param array)
Params is a keyword.
It is a concept of collecting all parameters into an array.
Param array Must be the last argument in a method.
One Method can have only one param array.
Example:
namespace ClassLibrary1
{
public class Class1
{
public int Add(int x,int y,params int [] a)
{
int i, sum = 0;
for (i = 0; i < a.Length; i++)
{
sum = sum + a[i];
}
return sum;
}
}
}
Calling:
Class1 obj=new Class1();
Int p= obj.Add(1,1,4,5,6,7,8);
P=30

Delegate:
A delegate in C# is similar to a function pointer in C or C++ but A Delegate is a type safe function
pointer that contains the details of a method(reference of the method) rather than the data.
Purpose of delegates in C#.Net:
a) Delegates can be used to define callback methods
b) Event Handling
c) improves the performance of application
Abstracting and encapsulating methods
1. Asynchronous programming
2. Sequential programming etc.

Delegates can be chained together; for example, multiple methods can be called on a single event.

Delegate general meaning " a person acting for another person" (i.e in C#.net it is really means a
method acting for another method.
There are four steps in defining and using delegates:

a) Delegate declaration
b) Delegate methods definition

c) Delegate instantiation
d) Delegate invocation.
Delegate is a pointer to a method. A delegate looks and behaves much like are ordinary when it is
called.
Example1:
namespace nNameSpace
{
//Declaration
public delegate void SimpleDelegate();
public class TestDelegate
{
public static void MyFunc()
{
Console.WriteLine("I was called by delegate ...");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
// Instantiation
SimpleDelegate simpleDelegate = new SimpleDelegate(TestDelegate.MyFunc);
// Invocation
simpleDelegate();
}

Example2:
namespace MyFirstDelegate
{
//This delegate can point to any method,
//taking two integers and returning an
//integer.
public delegate int MyDelegate(int x, int y);
//This class contains methods that MyDelegate will point to.
public class MyClass
{
public static int Add(int x, int y)
{
return x + y;
}
public static int Multiply(int x, int y)
{
return x * y;
}
}
protected void Button1_Click(object sender, EventArgs e)
{

//Create an Instance of MyDelegate


//that points to MyClass.Add().
MyDelegate del1 = new MyDelegate(MyClass.Add);
//Invoke Add() method using the delegate.
int addResult = del1(5, 5);
//Create an Instance of MyDelegate
//that points to MyClass.Multiply().
MyDelegate del2 = new MyDelegate(MyClass.Multiply);
//Invoke Multiply() method using the delegate.
int multiplyResult = del2(5, 5);
}

What is Multicast Delegate?


It is a delegate which holds the reference of more than one method.
Multicast delegates must contain only methods that return void, else there is a run-time exception.
they can point to more than one function at a time
Example1:
namespace MyMulticastDelegate
{
//this delegate will be used to call more than one
//method at once
public delegate void MulticastDelegate(int x, int y);
//This class contains methods that MyDelegate will point to.
public class MyClass
{
public static void Add(int x, int y)
{
Console.WriteLine("You are in Add() Method");
Console.WriteLine("{0} + {1} = {2}\n", x, y, x + y);
}
public static void Multiply(int x, int y)
{
Console.WriteLine("You are in Multiply() Method");
Console.WriteLine("{0} X {1} = {2}", x, y, x * y);
}
}
class Program
{
static void Main(string[] args)
{
//Create an Instance of MulticastDelegate
//that points to MyClass.Add().
MulticastDelegate del = new MulticastDelegate(MyClass.Add);
//using the same instance of MulticastDelegate
//to call MyClass.Multibly() by adding it to it's
//invocation list.
del += new MulticastDelegate(MyClass.Multiply);
//Invoke Add() and Multiply() methods using the delegate.

//Note that these methods must have a void return vlue


Console.WriteLine("****calling Add() and Multibly() Methods.****\n\n");
del(5, 5);
//removing the Add() method from the invocation list
del -= new MulticastDelegate(MyClass.Add);
Console.WriteLine("\n\n****Add() Method removed.****\n\n");
//this will invoke the Multibly() method only.
del(5, 5);
}
}
}

Collections:
collection classes are one type of array class.
collection classes are used for maintaining list of arrays.
Name Space: system.Collection
There are five types of collections in the .net framework
1.ArrayList
2.HashTable
3.SortedList
4.Queue and
5.Stack
What is an Array List?
In array list each item stored in sequential order
Array List contains a simple list of values.
.
Array List implements the IList interface using an array
Array List resizes dynamically.
Example:
/*
Q1.How
Q2.How
Q3.How
Q4.How
Q5.How

to
to
to
to
to

add an Item in an ArrayList ?


Insert an Item in an ArrayList ?
remove an item from arrayList ?
remove an item in a specified position from an ArrayList ?
sort ArrayList ?

*/
//Create an ArrayList and add three elements
ArrayList Villages = new ArrayList();

Villages.Add("bb"); //Add item to array list(Ans: for Q1)


Villages.Add("cc");
Villages.Add("aa");
Villages.Insert(0, "Villages in the States."); //Ans: for Q2.
Villages.Sort();// Sort the ArrayList.
Villages.Reverse();// Reverse the ArrayList.
ArrayList States = new ArrayList();
States.Add("A.P");
States.Add("U.P");
States.Add("M.P");
States.Add("Gova");
States.Add("Delhi");
//we can remove array list in 4 ways:
States.RemoveAt(1); //Remove element from specific location(start with 0).
States.Remove("M.P"); //Ans: for Q3
States.RemoveRange(0, 2); //Remove items from between the range
States.Clear();//Clear the items from ArrayList.
int arryCount = States.Count; //Show number of elements in ArrayList

Example:
ArrayList Villages = new ArrayList();
Villages.Add("bb");
Villages.Add("cc");
Villages.Add("aa");
ArrayList States = new ArrayList();
States.Add("A.P");
States.Add("U.P");
States.Add("M.P");
States.AddRange(Villages);//explicitly add begining of array list.
for (int i = 0; i < States.Count; i++)
{
string fName = States[i].ToString();
}
Output:
A.P
U.P
M.P
Bb
Cc
Aa

Difference between the array list and array?

Array
Array is fixed size in its
declaration

Array List
Array list similar to an array but
it does not have a limited size.
increased size dynamically.

Hash Table:
In hash table there is no sequential ordering of elements.
hash table indexes each element with a alphanumeric key.
example:
Hashtable hashtable = new Hashtable();
hashtable[1] = "One";
hashtable[2] = "Two";
hashtable[13] = "Thirteen";

Example1:
static Hashtable GetHashtable()
{
// Create and return new Hashtable.

Hashtable hashtable = new Hashtable();


hashtable.Add("Area", 1000);
hashtable.Add("Perimeter", 55);
hashtable.Add("Mortgage", 540);
}

return hashtable;

Example2:
static Hashtable GetHashtable()
{
Hashtable hashtable = new Hashtable();
hashtable.Add(300, "Carrot");
hashtable.Add("Area", 1000);
return hashtable;
}

Sorted List:
The sorted list class internally maintain two array's
1.A stored array of the key
2.An array of the value.

In sorted list elements(Items) stored based on the alphanumeric key and a numeric index.
Sorted list can be indexed by both key and value.
example:
Example1:
static Hashtable GetHashtable()
{
// Create and return new Hashtable.
SortedList mSortedList = new SortedList();

hashtable.Add("Area", 1000);
hashtable.Add("Perimeter", 55);
hashtable.Add("Mortgage", 540);
}

return hashtable;

Queue:
Arraylist,hashtable and sorted list allows random access to their elements but stock and queue
provide sequential access only.
Queue is the first-in first-out(FIFO) or last-in last-out(LILO) data structure
Stock:
stock is a data structure similar to a Queue. Is supports only sequential access.
Stack uses Last-in First out(LIFO) or First-in Last Out.

Stack perform two operations:


1.adding an elements to the top of the stock with push method and remove the elements from the top
of the stack.
Note: stock and queue classes contain peek method to perform developers to access the top of the
stock without removing the elements.
Generics
Explain why you should use generic collections
Use the Sorted List generic collection
Use generics with custom classes

Use the Queue and Stack collection generically


Use the generic List collection
Using generics, We can create strongly typed collections for any class, including custom
classes.
It can improve performance by reducing the number of casting operations required

Generic Collection Classes

Generic Class
List<T>
Dictionary<T,U>
Queue<T>

Comparable No generic Classes


ArrayList, StringCollection
Hashtable, ListDictionary, HybridDictionary,
OrderedDictionary, NameValueCollection,
StringDictionary
Queue

Generic SortedList<T,U> Collection


// C#
-------------------------------------------------------------------SortedList<string, int> sl = new SortedList<string, int>();
sl.Add("One", 1);
sl.Add("Two", 2);
sl.Add("Three", 3);
foreach (int i in sl.Values)
{
Response.Write(i.ToString());
}

Using Generics with Custom Classes:


We can use generics with custom classes as well

public class person


{
string firstName;
string lastName;
public person(string _firstName, string _lastName)
{
firstName = _firstName;
lastName = _lastName;
}
override public string ToString()
{
return firstName + " " + lastName;
}
}

We can use the SortedList<T,U> generic class with the custom Person.We would use it
with an integer
// C#
SortedList<string, person> sl = new SortedList<string,person>();
sl.Add("One", new person("Mark", "Hanson"));
sl.Add("Two", new person("Kim", "Akers"));
sl.Add("Three", new person("Zsolt", "Ambrus"));
foreach (person p in sl.Values)
{
Response.Write(p.ToString());
}

Generic Queue<T> and Stack<T> Collections


Queue<person> q = new Queue<person>();
q.Enqueue(new person("Mark", "Hanson"));
q.Enqueue(new person("Kim", "Akers"));
q.Enqueue(new person("Zsolt", "Ambrus"));
Response.Write("Queue demonstration:");
for (int i = 1; i <= 3; i++)
Response.Write(q.Dequeue().ToString());
Stack<person> s = new Stack<person>();
s.Push(new person("Mark", "Hanson"));
s.Push(new person("Kim", "Akers"));
s.Push(new person("Zsolt", "Ambrus"));
Response.Write("Stack demonstration:");
for (int i = 1; i <= 3; i++)
Response.Write(s.Pop().ToString());

Generic List<T> Collection


We can use generics with custom classes as well

public class person


{
string firstName;
string lastName;
public person(string _firstName, string _lastName)
{
firstName = _firstName;
lastName = _lastName;
}
override public string ToString()
{
return firstName + " " + lastName;
}
}

We can use the SortedList<T,U> generic class with the custom Person.We would use it
with an integer
// C#
SortedList<string, person> sl = new SortedList<string,person>();
sl.Add("One", new person("Mark", "Hanson"));
sl.Add("Two", new person("Kim", "Akers"));
sl.Add("Three", new person("Zsolt", "Ambrus"));
foreach (person p in sl.Values)
{
Response.Write(p.ToString());
}

There are two methods to develop the C#.net:


1.Branching
2.Looping
Branching:
There are three branching techniques available in C#.Net?
1.The ternary operator
2.If statement
3.switch statement

Ternary operator:
syntax: <condition>? <result if true> : <result if false>

Example:

int x = 10;
int y = 15;
if (x < y)
{
Response.Write("x is less than y");
}
else if (x > y)
{
Response.Write("x is larger than y");
}
else
{
Response.Write("x is equal to y");
}
String m = (x < y) ? "x less than y" : "x greater than y";

IF Statement:
syntax:
if(Boolean expression)
{
statement
}
else if(expression)
{
statement;
}
else
{
statement;
}

Switch statement:
syntax:
Switch(i)
{
Case 0:

Statement;
Break;
Case 1:

Statement;
Goto Default;
Break;
Default:

Statement
Break;
}

Looping:
1. for loops
2.while loops
3.do loop or do while loop
There are some interrupts in the loops:
1.break
2.continue
3.goto
4.return
For loop:
syntax:
For(initializer;condition;iteration)
{
Statements;
}

While loop:
syntax:
while(expression)
{
Statements;
}

do while loop:
syntax:
Do
{
Code to be looped;
While(<text>);
}

Interrupts in the loops:


break statement example:
int i = 1;
while (i < 10)
{
if (i == 6)
break;
Response.Write(i);
i = i + 1;
}

goto statement example:


int i = 1;
while (i < 10)
{
if (i == 6)
goto exitpoint;
Response.Write(i);
i = i + 1;
exitpoint:
Response.Write("Hi");
}

goto statement example:


int i = 1;
while (i < 10)
{
if (i == 6)
goto exitpoint;
Response.Write(i);
i = i + 1;
exitpoint:
Response.Write("Hi");
}

Structure:
A structure is simple used-defined value type.

structure is similar to the class. It also contain the fields , Properties , Methods , events and
constructor etc but it can't support the inheritance, destructors and default constructors.
By default all are public in structure. we can't initialize the values in structure like
Private int xVal=50;
Private int yVal=100;

Operators
Operators Name
Arithmetic operators
Logical(Boolean & bit
map)
String operator
Increment, decrement
Shift
Relational
Assignment
Type information
Indirection & Address
Type casting:
Type conversion:

Example:

Operators
+,-,*,/,%
&,/,^,!,~,&&,||,true, false
+
++,-<<,>>
==,!=,<,>,<=,>=
=,+=,-=,*=,!=,&=,%=,^=,<<=,>>=,?
Is,typeof,sizeof
*,->,[],&

Solution Explorer in ASP.Net:

Global.asax file:
This file contain global code for the web application.
It contain the even handling code for used to react the application.
Global.aspx page having the following events:

Example:
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to
StateServer
// or SQLServer, the event is not raised.

}
</script>

1.Application_Start: when the application receives the first user request the application
start event is fired.

2.Application_Start: When all the pending requests are completed the application end
event is fired and the application is restarted.

Difference between the C#.Net and Java?


Inline coding

Code behind page


CodeFile attribute is pint the class
file of the web form which is used
to write the server side code.

Web.config file:
1.Web.config files used to stored the connection string and global.aspx file also used to store the connection
string.

Example:
<configuration>
<appSettings>
<add key="Conn" value="Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=FinQuest;Data Source=LAXMAN-PC">
</add>
</appSettings>
</configuration>
How to call the connection string in web application:
string conn = "";
conn=System.Configuration.ConfigurationSettings.AppSettings["Conn"].ToString();

Note: we can use more than one web.config files in web applications.

How many configuration files are there:


1.Machine configuration file
2.Application configuration file
3.Security configuration file

Machine configuration file:


The machine configuration file, Machine.config, contains settings that apply to an entire computer.
This file is located in the %runtime install path%\Config directory

Application Configuration Files


Application configuration files contain settings specific to an application.
This file contains configuration settings that the common language runtime reads (such as assembly
binding policy, remoting objects, and so on), and settings that the application can read.
The name and location of the application configuration file depend on the application's host, which
can be one of the following:
a) Executablehosted application.
b) ASP.NET-hosted application.
c) Internet Explorer-hosted application.

Security Configuration Files:


The security configuration files are in the following locations:

Enterprise policy configuration file: %runtime-install-path%\Config\Enterprisesec.config


Machine policy configuration file: %runtime-install-path%\Config\Security.config
User policy configuration file: %USERPROFILE%\Application data\Microsoft\CLR security
config\vxx.xx\Security.config

Difference between the dispose() and finalize()?


Finalize

Finalize() method called by garbage


collector at runtime when an object is
no longer referenced

Dispose

Dispose() method is called by the code


explicitly to dispose any object when
needed by the program such as if there
are unmanaged

Finalize () is called by Garbage


Collector implicitly to free unmanaged
resources

Difference between the string and StringBuilder();


String

String Builder

Potrebbero piacerti anche