TOPPERS NOTES II IT
TOPPERS NOTES II IT
UNIT - I
.NET:
.NET stands for Network Enable Technology which is developed by Microsoft Corporation.
.NET is a collection of languages like VC#.NET, VC++.NET, VB.NET and so on.
.NET is a Framework which provides a common platform to Execute or Run the applications
developed in various programming languages.
.NET Objectives: The .NET Framework is designed to fulfil the following objectives
Platform independent: As .exe and .dll files work in any operating system with the help of
CLR, hence .Net is called as platform independent.
(.exe) is executable file, it consists of executable code, and (.dll) is dynamic link library file it
consist of reusable code. .exe and .dll files contains the code in the format of byte code is also
called as MSIL (Microsoft intermediate language) code.
Machine language is also called as native code. CLR is common language runtime; CLR
software converts byte code into native code. Dot Net is platform independent but CLR
software is platform dependent.
One question arises if we go in detail, that is either Dot Net is pure platform independent or
not? Answer is Dot Net is partially platform dependent, as of now CLR software's are not
available for DOS operating system and Windows 95.
Language independent: As Dot Net programming logic can be developed in any Dot Net
framework compatible languages; hence Dot Net is called as language independent.
Microsoft is introducing approximately 40 languages into Dot Net framework, out of which as
of now approximately 24 languages and one specification are released. Ex:
VC#.Net,VB.Net,VC++,VJ#,VF#,PHP,COBOL,PERL,PHYTHON,SMALLTALK,JSCRI
PT...etc One specification is ASP.Net.
Language interoperability: It is a concept of developing an application with the help of
more than one .NET programming language. After an application is compiled, the source
code will be converted into byte code. Byte code follows a standard instruction set provided
by cls(common language specification).Cls provides common rules and syntaxes for all the
languages and cls also provides common data types for all the languages and these common
data types are called as CTS(common type system).
C++ C# VB .NET
int(2) short(2) short(2)
long(4) int(4) integer(2)
long(8) long(8)
SYSTEM.INT16
SYSTEM.INT32
SYSTEM.INT64
It supports object-oriented programming environment.
It supports to work with database programming with the help of ADO.NET.
It supports to work with WPF (windows presentation foundation) for developing animations.
It Provides environment for developing various types of applications, such as Windows-
based applications and Web-based applications
It Supports to develop 3-tier architecture with the help of Dot Net remoting
Supports to develop game programming with the help of multi-threading
Supports to work with link programming
Managed Code: The code is developed and running under the control of the CLR is often termed
managed code
Unmanaged code: The code which takes OS help while execution is called as unmanaged code
Note: Managed code is faster in execution.
Unmanaged code
CLR
.net .dll
.exe Output
Managed code
The .Net framework is a revolutionary platform that helps you to write the following types of
applications:
Windows applications
1.0 2002
1.1 2003
2.0 2005
3.0 2006
3.5 2007
4.0 2009
The .Net framework consists of an enormous library of codes used by the client languages
such as C#. Following are some of the components of the .Net framework:
Common Language Runtime (CLR)
The .Net Framework Class Library
Common Language Specification
Common Type System
Metadata and Assemblies
Windows Forms
ASP.Net and ASP.Net AJAX
ADO.Net
Windows Workflow Foundation (WF)
Windows Presentation Foundation
Windows Communication Foundation (WCF)
LINQ
.NET framework architectural diagram: The .NET framework is one of the tool provided by
the .NET infrastructure and tools component of the .NET platform. The .NET framework provides an
environment for building, deploying and running web services and .NET applications.
PLINQ TPL
LINQ ADO.NET ENTITY FRAMEWORK
WPF WCF WF CARD SPACE
ADO.NET ASP.NET WIN FORMS
BASE CLASS LIBRARIES
In C#, some identifiers have special meaning in context of code, such as get and set, these are called
contextual keywords.
User defined types (or) complex types: Here we can define our own complex types known as
User defined value types, which includes
structures
enumerations
Predefined types: These are also known as simple types (or) primitive types. Predefined types are
divided into
Numeric types
Boolean types
Character types
Numeric types: Numeric types include integral types, floating point types and decimal types.
Integral types: Integral types can hold whole numbers such as 123, -96 and 5639.The size of the
values that can be stored depends on the integral data type we choose. C# supports the concept of
unsigned types and therefore it supports eight types of integers .
Signed integers: signed integer types can hold both positive and negative numbers.
Type Size Minimum value Maximum value
sbyte 1 byte -128 +127
short 2 byte -32768 +32767
int 4 byte 2147483648 +2147483647
long 8 byte -9223372036854775808 +9223372036854775807
Unsigned integers: unsigned integer types can hold only positive numbers
Type Size Minimum value Maximum value
byte 1 byte 0 255
ushort 2 byte 0 65535
uint 4 byte 0 4294967295
ulong 8 byte 0 18446744073709551615
All integers are by default int type. In order to specify other integer types, we must append the
characters U,L or UL
123U(for uint type)
123L(for long type)
123UL(for ulong type)
Floating point types: Floating point types hold numbers containing fractional parts such as 27.59
and -1.375.There are two kinds of Floating point storage in C#
The Floating point values are single-precision numbers with a precision of seven digits.
The double types represent double-precision numbers with a precision of 15/16 digits
Type Size Minimum value Maximum value
float 4 byte 1.5x10-45 3.4x1038
double 8 byte 5.0x10-324 1.7x10308
Floating point numbers by default as double-precision quantities.to force them to be in single
precision mode, we must append f (or) F to the numbers.
Example: 1.23f
7.56923f
Double-precision types are used when we need greater precision in storage of floating-point
numbers.
Floating-point data types support a special value known as Not-a-Number(NaN).NaN is used to
represent the result of operations such as dividing zero by zero,where an actual number is not
produced. Most operations NaN as an operand will produce NaN as result.
Decimal type: The decimal type is a high precision,128-bit data type that is designed for use in
financial monetary calculations. It can store values in the range 1.0x10 -28 to 7.9x1028 with 28
significant digits.
To specify a number to be decimal type, we must append the character M or mto the value.
Example: 123.45M (if we omit M, the value will be treated as double).
Character type: In order to store single characters in memory, C# provides a character data type
called char. The char type assumes a size of two bytes but, in fact it can hold only a single
character. char data type has been designed to hold a 16-bit Unicode character, in which 8-bit ASCII
code is a subset.
Boolean type: Boolean condition can be used when we want to test a particular condition during the
execution of the program. There are two values that a Boolean type can take true (or) false. Boolean
type can be denoted by the keyword bool and uses only one bit of storage.
Reference types: reference types (which are of variable length) are stored on the heap, and when an
assignment between two reference variables occurs, only the reference is copied. The actual values
remains in the same memory location. This means there are two references to a single value. The
reference types can be divided into two groups
User defined types (or) complex types
Predefined types (or) simple types
User defined types: user defined reference types refer to those types which we define using
predefined type. They include
Classes
Delegates
Interfaces
Arrays
Predefined types: Predefined types include two types
Object type
String type
VARIABLES: A variable is an identifier that denotes a storage location uses to store a data value.
Unlike constants that remain unchanged during the execution of the program, a variable may take
different values at different times during the execution of the program. Every variable has a type that
determines what values can be stored in the variable.
Rules for forming a variable:
They must not begin with a digit.
Uppercase and lower case is distinct. This means that the variable TOTAL is not same as
total or Total.
It should not be a keyword.
White space is not allowed.
Variable names can be of any length.
Variable declaration: After designing suitable variable names, we must declare the variable before it
used in the program. Declaration does three things
It tells the compiler what the variable name is.
It specifies what type of data the variable will hold.
The place of declaration in the program decides the scope of the variable.
Syntax: data_type variable1, variable2,……. variableN;
Here, data_type must be a valid C# data type including char, int, float, double, or any user-defined data
type, and variables are separated by commas. Some valid variable definitions are shown here:
int i, j, count;
float f, salary;
double pi;
byte b;
char c1,c2,c3;
decimal d1,d2;
uint m;
ulong n;
Initializing Variables: The process of giving initial values to the variables is called initialization. Once
the declaration has been done then initializes the variables with the assignment operator. The general
form of initialization is:
Syntax: variable_name = value;
It is also possible to assign a value at the time of its declaration.
Syntax: <data_type> <variable_name> =
value; Example:
int d = 3, f = 5;
byte z = 22;
double pi = 3.14159;
char x = 'x';
Example:
float x,y,z; //declares three variables
int m=5,n=10; //declares and initializes two int
variables int m, n=10; //declares m and n and initializes n.
Example: The following example uses various types of variables:
using System;
namespace VariableDefinition
{
class Program
{
static void Main(string[] args)
{
short a; int b ; double c;
/* actual initialization */
a = 10; b = 20; c = a + b;
Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c);
Console.ReadLine();
}
}
}
Output: a = 10, b = 20, c = 30
Scope of variables: The scope of the variable determines over what part(s) of the program a variable
is actually available for use (active).This depends on the type of the variable and place of its
declaration. C# defines several categories of variables.
Static variables
Instance variables
Array elements
Value parameters
Reference parameters
Output parameters
Local variables
Example: class ABC
{
static int m;
int n;
void fun (int x , ref int y, out int z, int[] a)
{
int j = 10;
}
}
m = static variable,
n = instance variable,
x = value parameter,
y = reference parameter,
j = local variable,
z =output parameter,
a[0] = array element
TYPE CONVERSION: The process of converting one data type into another data type is known as
type casting or type conversion. Type conversions are divided into two types.
1. Implicit (or) up casting (or) widening (or) automatic type conversion.
2. Explicit (or) down casting (or) narrowing type conversion.
Implicit type conversion (Automatic type conversion): Converting lower data type into higher
data type is called widening. In this one data type is automatically converted into another type as per
the rules described in c# language, which means the lower level data type is converted automatically
into higher level data type before the operation proceeds. The result of the data type having higher
level data type.
Example: byte x = 12;
int y = x;
In the above statement, the conversion of data from byte to int is done implicitly, in other words
programmers don‘t need to specify any type operators. Widening is safe because there will not be
any loss of data. This is the reason even though the programmer does not use the cast operator the
compiler does not complaint because of lower data type is converting into higher data type. Here
higher data type having the much more space to store the lower data type.
Example: using System;
namespace explicit_cast_conversion
{
class Program
{
static void Main(string[] args)
{
int num1=10;
long num2=num1;
Console.WriteLine("num2 value is : " +num2);
Console.ReadLine();
}
}
}
Explicit type conversion: Converting higher data type into lower data type is called
narrowing. Here we can place intended data type in front of the variable to be cast.
Syntax: data-type variablename1=(cast-
type)variablename2; Example: double d=12.67853;
int n = (int) d;
Here we are converting higher level data type into lower level data type that means double type is
converted into int type, the fractional part of the number is lost and only 12 is stored in n. Here we
are losing some digits this is the reason the compiler forces the programmer to use the cast operator
when going for explicit casting.
Example:
using System;
class Program
{
static void Main()
{
string text = "500";// Convert string to number.
int num = int.Parse(text);
Console.WriteLine(num);
int num2 = int.Parse(Console.ReadLine());
Console.WriteLine(num2);
}
}
Example: using System;
namespace parsing
{
class Program
{
static void Main(string[] args)
{
int number;
float weight;
Console.Write("Enter any number : ");
number = int.Parse(Console.ReadLine());
Console.Write("Enter your weight : ");
weight = float.Parse(Console.ReadLine());
Console.WriteLine("You have entered : " + number);
Console.WriteLine("You weight is : " + weight);
Console.ReadLine();
}
}
}
Convert class: It is used to convert one primitive type to another primitive type. Convert is the
predefined class. C# provides the following built-in type conversion methods as described:
S.No Method Description
1 ToBoolean Converts a type to a Boolean value, where possible
2 ToByte Converts a type to byte.
3 TOChar Converts a type to single Unicode character, where possible.
4 ToDateTime Converts a type to date time structures.
5 ToDecimal Converts a floating point or integer type to decimal type.
6 ToDouble Converts a type to double type.
7 ToInt16 Converts a type to a 16-bit integer.
8 ToInt32 Converts a type to a 32-bit integer.
9 ToInt64 Converts a type to a 64-bit integer.
10 ToSbyte Converts a type to a signed byte type.
11 ToSingle Converts a type to a small floating point number.
12 ToString Converts a type to a string.
13 ToType Converts a type to a specified type.
14 ToUInt16 Converts a type to unsigned int type.
15 ToUInt32 Converts a type to unsigned long type.
16 ToUInt64 Converts a type to unsigned big integer.
Example: The following example converts various value types to string type:
using System;
namespace TypeConversionApplication
{
class StringConversion
{
static void Main(string[] args)
{
int i = 75;
float f = 53.005f;
double d = 2345.7652;
bool b = true;
Console.WriteLine(i.ToString());
Console.WriteLine(f.ToString());
Console.WriteLine(d.ToString());
Console.WriteLine(b.ToString());
Console.ReadKey();
}
}
}
Output: 75
53.005
2345.7652
True
Example:
using System;
namespace Arithmetic_Operators
{
class Program
{
static void Main(string[] args)
{
int num1, num2;
int add, sub, mul;
Console.Write("Enter first number\t\t");
num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("\n\nEnter second number\t\t");
num2 = Convert.ToInt32(Console.ReadLine());
add = num1 + num2;
sub = num1 - num2;
mul = num1 * num2;
Console.WriteLine("\n\n=============\n");
Console.WriteLine("Addition\t\t{0}", add);
Console.WriteLine("Subtraction\t\t{0}", sub);
Console.WriteLine("Multiplication\t\t{0}", mul);
Console.WriteLine("\n==============\n");
Console.ReadLine();
Arithmetic Operators
Relational Operators
Logical Operators
Assignment Operators
Increment and decrement operators
Conditional operators
Bitwise Operators
Special Operators
Arithmetic Operators: The operators that are used to perform Arithmetic operations such as
addition, subtraction, multiplication, ----etc. are called Arithmetic operators. Assume variable A
holds 10 and variable B holds 20 then:
Operator Meaning Description Example
+ Addition operator Adds two operands a+b=30
- Subtraction operator Subtracts second operand from the first a-b=-10
* Multiplication operator Multiplies both operands a*b=200
/ Division operator Divides numerator by de-numerator b/a=2
% Modulus division operator It gives Remainder after an integer division b%a=0
Integer Arithmetic: When both the operands in a single arithmetic expression such as a+b are
integers, the expression is called as integer expression and the operation is called integer arithmetic
The a=4, b=2, then
a+b = 6
a-b = 2
a*b = 8
a/b = 2
a%b = 0
Real Arithmetic: An arithmetic operation involving only real operands is called real arithmetic. A
real operand may assume values either in decimal or exponential notation.
Example: a=20.5F,b=6.4F
a+b =26.9
a-b = 14.1
a*b = 131.2
a/b = 3.203125
a%b = 1.3
Example:
Mixed-mode Arithmetic: When one of the operands is real and the other is integer, the expression is
called a mixed-mode arithmetic expression. If either operand is real type, then the other operand is
converted to real and real arithmetic is performed. The result will be real.
Example: 15/10.0=1.5
15.0/10=1
Example: The following example demonstrates all the arithmetic operators available in C#:
using System;
namespace OperatorsAppl
{
class Program
{
static void Main(string[] args)
{
int a = 21;
int b = 10;
int c;
c = a + b;
Console.WriteLine("Line 1 - Value of c is {0}",
c); c = a - b;
Console.WriteLine("Line 2 - Value of c is {0}",
c); c = a * b;
Console.WriteLine("Line 3 - Value of c is {0}",
c); c = a / b;
Console.WriteLine("Line 4 - Value of c is {0}",
c); c = a % b;
Console.WriteLine("Line 5 - Value of c is {0}",
c); c = a++;
Console.WriteLine("Line 6 - Value of c is {0}",
c); c = a--;
Console.WriteLine("Line 7 - Value of c is {0}", c);
Console.ReadLine();
}
}
}
Output: Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2
Line 5 - Value of c is 1
Line 6 - Value of c is 21
Line 7 - Value of c is 22
Relational Operators: These operators are used to compare the value of two variables. Relational
operator‘s checks relationship between two operands. If the relation is true, it returns value
1 and if the relation is false, it returns value 0. Assume variable A holds 10 and variable B holds
20, then:
Operator Meaning Description Example
> Greater than Checks if the value of left operand is greater than (a>b)
the value of right operand, if yes then condition is not
becomes true. true
< Less than Checks if the value of left operand is less than (a<b)
the value of right operand, if yes then condition is
becomes true. true
<= Less than or equals to Checks if the value of left operand is less than or a<=b is
equal to the value of right operand, if yes then true
condition becomes true.
>= Greater than or equals to Checks if the value of left operand is greater than a>=b
or equal to the value of right operand, if yes then is not
condition becomes true. true
!= Not equals to Checks if the values of two operands are equal or a!=b
not, if values are not equal then condition is
becomes true. true
== Equals to Checks if the values of two operands are equal or a==b is
not, if yes then condition becomes true. not true
Example: The following example demonstrates all the relational operators available in C#:
using System;
class Program
{
static void Main(string[] args)
{
int a = 21;int b = 10;
if (a == b)
Console.WriteLine("Line 1 - a is equal to b");
else
Console.WriteLine("Line 1 - a is not equal to b");
if (a < b)
Console.WriteLine("Line 2 - a is less than b");
else
Console.WriteLine("Line 2 - a is not less than b");
if (a > b)
Console.WriteLine("Line 3 - a is greater than b");
else
Console.WriteLine("Line 3 - a is not greater than b");
a = 5;
b = 20;
if (a <= b)
Console.WriteLine("Line 4 - a<=b");
if (b >= a)
Console.WriteLine("Line 5-b >=b");
}
}
Output: Line 1 - a is not equal to b
Line 2 - a is not less than b
Line 3 - a is greater than b
Line 4 - a is either less than or equal to b
Line 5 - b is either greater than or equal to b
Logical Operators: These operators are used to perform logical operations on the given two
variables. Logical operators are used to combine expressions containing relation operators.
Assume variable A holds Boolean value true and variable B holds Boolean value false, then:
Operator Meaning Description Example
&& Logical AND If both operands are non-zero then condition (a&&b) is false
becomes true
|| Logical OR If any of the two operands is non-zero then (a||b) is true
condition becomes true
! Logical NOT Used to reverse the logical state of its !(a&&b) is true
operand. If a condition is true then logical
NOT operator will make false.
Example: The following example demonstrates all the logical operators available in C#:
using System;
namespace OperatorsAppl
{
class Program
{
static void Main(string[] args)
{
bool a = true;
bool b =
true; if (a
&& b)
Console.WriteLine("Line 1 - Condition is true");
if (a || b)
Console.WriteLine("Line 2 - Condition is true");
/* lets change the value of a and b */
a = false;
b = true;
if (a && b)
Console.WriteLine("Line3-Condition is true");
else
Console.WriteLine("Line3-not true");
if (!(a && b))
Console.WriteLine("Line4-Condition is true");
Console.ReadLine();
}
}
}
Output: Line 1 - Condition is true
Line 2 - Condition is true
Line 3 - Condition is not true
Line 4 - Condition is true
Assignment Operators: These are used to assign the values for the variables in C# programs. The
most common assignment operator is =.The syntax is shown below:
data type Variable_name = expression;
Miscellaneous Operators: There are few other important operators including sizeof, typeof and ? :
supported by C#.
**********UNIT-1 COMPLETED******