0% found this document useful (0 votes)
22 views

Module 1

Uploaded by

mr.arjunb27
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Module 1

Uploaded by

mr.arjunb27
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 137

BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Department of MCA

Advanced Programming -21MCA303

Handling By
Nirupama K
Asst. Prof. Dept. of MCA
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
What is .NET ?
Microsoft.NET is a Framework
• Microsoft .NET is a Framework which provides a common
platform to Execute or, Run the applications developed in
various programming languages.

• The main intention was to bridge the gap in


interoperability between services of various
programming languages.

2
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Evolution of .NET
• Mid ninety Java was most popular because of platform independent and
open source from Sun Microsoft
• In the year 2002 new edition of Java J2EE
• Microsoft released the first version of .NET with the name .NET
framework 1.0 Feb 2002
• To release 2nd version they took one year that version is known as Visual
Studio NET 2003
• Next release in the year 2005
• In the year 2008 NET 3.5 is released
• In the year 2010 NET 4.0 is released

04/04/2024 3
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Introduction
• NET framework is an essential component of window operating system
• Programming languages C#, J#, VB and Visual C++
• 3 important components CRL, CLS, CTS
• NET framework is a bridge between applications which are created using
C#, Visual Basic
• Evolution
o Mid 90s java was popular to develop the application
o 2002 J2EE introduced
o February 10 2002 .Net framework 1.0 released along with visual
studio IDE

04/04/2024 4
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
.NET Framework Objectives

• The .NET Framework is designed to fulfill the following


objectives:
• Provide object-oriented programming environment

• Provide environment for developing various types of


applications, such as Windows-based applications and Web-
based applications

• To ensure that code based on the .NET Framework can


integrate with any other code

5
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Benefits of .NET Framework
• Consistent Programming Model- Provides a consistent object-oriented
programming model across different languages.
• Cross-platform support- specifies that any window platform that
support CLR can execute .NET application, that is, .NET application
enables interoperability between multiple windows operating system.
• Language Interoperability- Enable code written in different language to
interact with each other .
• Automatic Management of Resources- Specifies that in .NET you do not
need to manually free the application resources, such as files, memory,
network and database connection.
• Ease of deployment - specifies that the .NET framework install
applications or components that do not effect the existing application

04/04/2024 6
. BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
NET Framework

Visual Studio 2008


VB C++ C# JScript …

Common Language Specification

Windows
ASP.NET ADO.NET
Forms

Base Class Library

(CLR) Common Language Runtime

Operating System
. BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT

NET Framework architecture

04/04/2024 8
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
The Components of .NET Framework :
• Most important component of .NET framework
• Memory management, exception handling, debugging, security, thread
execution
• Managed code- executes directly by the CLR- selecting language
compiler, compiling the code to IL, compiling IL to native mode, execute
the code
• CLR also support for various resources such as collections, arrays,
operating system folder
• Runtime automatically releases the object when they are no longer in
use
• Unmanaged code
Common Type Specification (CTS)
• CTS specifies certain guidelines for declaring, using and managing types
at runtime
• Helps in cross language specification
04/04/2024 9
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Common Language Runtime (CLR)
• Most important component of .NET framework
• Memory management, exception handling, debugging, security, thread
execution
• Managed code- executes directly by the CLR- selecting language
compiler, compiling the code to IL, compiling IL to native mode, execute
the code
• CLR also support for various resources such as collections, arrays,
operating system folder
• Runtime automatically releases the object when they are no longer in
use
Managed Code
• Managed code is directly executed by CLR this code is automatically
have CLR services such as type checking, security and automatic garbage
collection.
• CLR complies the application to intermediate language and not machine
code
04/04/2024 10
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Unmanaged code
• It can directly compile to the machine code and runs on the machine
where it has been compiled
• This code does not have services such as security, memory management
Memory Management
• One of the most important service provided by CLR during managed
execution, automatic memory management
• CLR uses garbage collector to manage the allocation and release the
memory for an application
• Automatic memory management removes common problem such as
forgetting to free an object which results in memory leak
Common type specification (CTS)
CTS specifies certain guidelines for declaring, using and managing types at
runtime
Helps in cross language specification

04/04/2024 11
• Vccbvcb
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
• Support Object oriented model for implementation of different
programming languages
• Support primitive data types

04/04/2024 12
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Common Language Specification
CLS performs the following functions:
• Establishes a framework that helps enable cross-language integration,
type safety, and high performance code execution
• Provides an object-oriented model that supports the complete
implementation of many programming languages
• Defines rules that languages must follow, which helps ensure that
objects written in different languages can interact with each other

04/04/2024 13
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Assembly Contents : It has 4 elements they are as follows
• Assembly Manifest: Contains data that describe how elements are
related to each other within the assembly
• Global Assembly Cache(GAC):
• Strong Name Assembly:
• Private and Shared assembly:
• Side-by-side Execution Assembly:
• .NET Framework Class Library:
• Windows Form:
• ASP .NET and ASP .NET AJAX:
• ADO .NET:

04/04/2024 14
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Windows Workflow Foundation (WWF)
• Activities
• Workflow designer
• Workflow Runtime
• Rules Engine

04/04/2024 15
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Windows Presentation Foundation (WPF)

04/04/2024 16
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Windows Communication Foundation
(WCF)

04/04/2024 17
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Exploring the features of Net Framework
• Improvement in the application compatibility and deployment
• Dynamic language runtime
• Managed extensibility framework
• Parallel computing
• Improved security model
• Networking improvement
• Improvement in WPF
• Improved entity framework
• Integration of WCF and WF
• Improved code ASP .NET services

04/04/2024 18
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Introduction to C# (C Sharp)
• Microsoft C# (pronounced C Sharp) developed by Microsoft
Corporation, USA
• New programming language that runs on the .NET Framework
• C# is simple, modern, type safe, and object oriented
• C# code is compiled as managed code
• Combines the best features of Visual Basic, C++ and Java

19
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
C# Features
• Type-Simple
• Modern
• Object-Oriented
• Versionable
• Compatible
• Secure

20
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Sample Hello world program

04/04/2024 21
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Basics of C#
• Identifier
• Keywords
• Operators
• Variables
• Literal
• Constant
• Expressions
• Declaring statement
• Executable statement

04/04/2024 22
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Creating console application
• Understanding System namespace
• Data types
• Boolean
Byte
Char
Date
Decimal
Double
Integer
Long
Object
• Declaring variable and constant

04/04/2024 23
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Most commonly used namespace
• using System;
• using System.Collections.Generic;
• using System.Data;
• using System.Drawing;
• using System.Linq;
• using System.Text;
• using System.Windows.Forms;
• using System.Data.SqlClient;

04/04/2024 24
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT

04/04/2024 25
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT

04/04/2024 26
#
Introduction to C
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Prerequisites
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Learning Objectives
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Hello World

using System;

class Hello {
static void Main( ) {
Console.WriteLine("Hello world");
Console.ReadLine(); // Hit enter to finish
}
}
BMS
Agenda INSTITUTE OF TECHNOLOGY AND MANAGEMENT
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
The Big Ideas
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
Component-Orientation
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
Component-Orientation
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
Everything is an Object
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
Robust and Durable Software
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Design Goals of C#
Preserving Your Investment
BMS
Agenda INSTITUTE OF TECHNOLOGY AND MANAGEMENT
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Overview
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Overview
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Overview
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Types Unified Type System

int i = 123; i 123


string s = "Hello world";
s "Hello world"
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Types Unified Type System

• Value types
• Primitives int i; float x;
• Enums enum State { Off, On }
• Structs struct Point {int x,y;}
• Reference types
• Root object
• String string
• Classes class Foo: Bar, IFoo {...}
• Interfaces interface IFoo: IBar {...}
• Arrays string[] a = new string[10];
• Delegatesdelegate void Empty();
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Types Unified Type System

Value (Struct) Reference (Class)


Variable holds Actual value Memory location

Allocated on Stack, member Heap

Nullability Always has value May be null

Default value 0 null

Aliasing (in a scope) No Yes

Assignment means Copy data Copy reference


BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Unified Type System


BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Types Conversions
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Types Conversions

int x = 123456;
long y = x; // implicit
short z = (short)x; // explicit

double d = 1.2345678901234;
float f = (float)d; // explicit
long l = (long)d; // explicit
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Object

o b ject

S tream H ash tab le in t d o ub le

M em o ryS tream F ileS tream


BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Unified Type System

void Poly(object o) {
Console.WriteLine(o.ToString());
}
Poly(42);
Poly(“abcd”);
Poly(12.345678901234m);
Poly(new Point(23,45));
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Hint
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Boxing and Unboxing
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Boxing and unboxing

i 123
int i = 123;

object o = i; o System.Int32
123
int j = (int)o;
j 123
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Benefits of boxing
• Enables polymorphism across all types
• Collection classes work with all types
• Eliminates need for wrapper classes
• Replaces OLE Automation's Variant
• Lots of examples in .NET Framework
using System;
namespace lab project
{
class program2
{
/* C# program -Boxing and Un Boxing */

public static void Main()


{
Console.WriteLine ("Enter the Number");
int n = int.Parse (Console.ReadLine ());
object ob = n;
Console.WriteLine ("The Value of ob is {0}", ob);
int s = (int)ob;
Console.WriteLine ("The Value of s is {0}", s);
Console.ReadLine();
}}}
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Unified Type System


BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Predefined Types
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Value
Types

Signed sbyte, short, int, long

Unsigned byte, ushort, uint, ulong

Character char

Floating point float, double, decimal

Logical bool
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Integral Types
C# Type System Type Size (bytes) Signed?
sbyte System.Sbyte 1 Yes
short System.Int16 2 Yes
int System.Int32 4 Yes
long System.Int64 8 Yes
byte System.Byte 1 No
ushort System.UInt16 2 No
uint System.UInt32 4 No
ulong System.UInt64 8 No
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
Floating Point Types

C# Type System Type Size (bytes)


float System.Single 4
double System.Double 8
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
decimal

C# Type System Type Size (bytes)

decimal System.Decimal 16
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
decimal
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
Integral Literals

123 // Decimal
0x7B // Hexadecimal
123U // Unsigned
123ul // Unsigned long
123L // Long
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
Real Literals

123f // Float
123D // Double
123.456m // Decimal
1.23e2f // Float
12.3E1M // Decimal
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
bool

C# Type System Type Size (bytes)


bool System.Boolean 1 (2 for arrays)
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
char

C# Type System Type Size (bytes)


Char System.Char 2
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
char

Char Meaning Value


\’ Single quote 0x0027
\” Double quote 0x0022
\\ Backslash 0x005C
\0 Null 0x0000
\n New line 0x000A
\r Carriage return 0x000D
\t Tab 0x0009
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
Reference Types

Root type object

Character string string


BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
object

C# Type System Type Size (bytes)


object System.Object 0/8 overhead
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
object Public Methods
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
string

C# Type System Type Size (bytes)


String System.String 20 minimum
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Predefined Types
string

• Normally have to use escape characters

string s1= “\\\\server\\fileshare\\filename.cs”;

• Verbatim string literals


• Most escape sequences ignored
• Except for “”
• Verbatim literals can be multi-line

string s2 = @“\\server\fileshare\filename.cs”;
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

User-defined Types

Enumerations enum

Arrays int[], string[]

Interface interface

Reference type class

Value type struct

Function pointer delegate


BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Enums
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Types
Enums

enum Color: byte {


Red = 1,
Green = 2,
Blue = 4,
Black = 0,
White = Red | Green | Blue
}

Color c = Color.Black;
Console.WriteLine(c); // 0
Console.WriteLine(c.Format()); // Black
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Enums
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Arrays
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Arrays
• Declare
int[] primes;

• Allocate
int[] primes = new int[9];
• Initialize
int[] prime = new int[] {1,2,3,5,7,11,13,17,19};
int[] prime = {1,2,3,5,7,11,13,17,19};

• Access and assign


prime2[i] = prime[i];
• Enumerate
foreach (int i in prime) Console.WriteLine(i);
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Arrays
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Interfaces
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Classes
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Classes
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Structs
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Types
Classes and Structs

struct SPoint { int x, y; ... }


class CPoint { int x, y; ... }

SPoint sp = new SPoint(10, 20);


CPoint cp = new CPoint(10, 20);

10
sp
20

cp CPoint

10
20
BMS
Types INSTITUTE OF TECHNOLOGY AND MANAGEMENT

Delegates
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Overview
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Organizing Types

Assembly
Module
File
Type
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Organizing Types
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Organizing Types
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Namespaces
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Namespaces

namespace N1 { // N1
class C1 { // N1.C1
class C2 { // N1.C1.C2
}
}
namespace N2 { // N1.N2
class C2 { // N1.N2.C2
}
}
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Namespaces

using N1;

C1 a; // The N1. is implicit


N1.C1 b; // Fully qualified name

C2 c; // Error! C2 is undefined
N1.N2.C2 d; // One of the C2 classes
C1.C2 e; // The other one
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Namespaces

using C1 = N1.N2.C1;
using N2 = N1.N2;

C1 a; // Refers to N1.N2.C1
N2.C1 b; // Refers to N1.N2.C1
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Namespaces
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
References

csc HelloWorld.cs /reference:System.WinForms.dll


BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Namespaces vs. References
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure Main Method
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Program Structure
Syntax
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements Overview

void Foo() {
i == 1; // error
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Overview

• Statement lists  Loop Statements


 while
• Block statements  do
• Labeled statements  for
• Declarations  foreach
• Constants  Jump Statements
• Variables  break
• Expression statements
 continue
 goto
• checked, unchecked
 return
• lock
 throw
• using
 Exception handling
• Conditionals  try
• if  throw
• switch
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Syntax
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Syntax
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements Statement Lists & Block
Statements

static void Main() {


F();
G();
{ // Start block
H();
; // Empty statement
I();
} // End block
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Variables and Constants

static void Main() {


const float pi = 3.14f;
const int r = 123;
Console.WriteLine(pi * r * r);

int a;
int b = 2, c = 3;
a = 1;
Console.WriteLine(a + b + c);
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Variables and Constants
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Variables and Constants

{
int x;
{
int x; // Error: can’t hide variable x
}
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Variables

void Foo() {
string s;
Console.WriteLine(s); // Error
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Labeled Statements & goto

static void Find(int value, int[,] values,


out int row, out int col) {
int i, j;
for (i = 0; i < values.GetLength(0); i++)
for (j = 0; j < values.GetLength(1); j++)
if (values[i, j] == value) goto found;
throw new InvalidOperationException(“Not found");
found:
row = i; col = j;
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Expression Statements

static void Main() {


int a, b = 2, c = 3;
a = b + c;
a++;
MyClass.Foo(a,b,c);
Console.WriteLine(a + b + c);
a == 2; // ERROR!
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
if Statement

int Test(int a, int b) {


if (a > b)
return 1;
else if (a < b)
return -1;
else
return 0;
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
switch Statement
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
switch Statement
int Test(string label) {
int result;
switch(label) {
case null:
goto case “runner-up”;
case “fastest”:
case “winner”:
result = 1; break;
case “runner-up”:
result = 2; break;
default:
result = 0;
}
return result;
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
while Statement

int i = 0;
while (i < 5) {
...
i++;
} int i = 0;
do {
...
i++;
}
while (i < 5);
while (true) {
...
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
for Statement

for (int i=0; i < 5; i++) {


...
}
for (;;) {
...
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
foreach Statement

public static void Main(string[] args) {


foreach (string s in args)
Console.WriteLine(s);
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
foreach Statement

foreach (Customer c in customers.OrderBy("name")) {


if (c.Orders.Count != 0) {
...
}
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Jump Statements
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Exception Handling
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Exception Handling
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Exception Handling
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Exception Handling

try {
Console.WriteLine("try");
throw new Exception(“message”);
}
catch (ArgumentNullException e) {
Console.WriteLine(“caught null argument");
}
catch {
Console.WriteLine("catch");
}
finally {
Console.WriteLine("finally");
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Synchronization
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Synchronization
public class CheckingAccount {
decimal balance;
public void Deposit(decimal amount) {
lock (this) {
balance += amount;
}
}
public void Withdraw(decimal amount) {
lock (this) {
balance -= amount;
}
}
}
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
using Statement
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
using Statement
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
using Statement

public class MyResource : IDisposable {


public void MyResource() {
// Acquire valuble resource
}
public void Dispose() {
// Release valuble resource
}
public void DoSomething() {
...
}
}
using (MyResource r = new MyResource()) {
r.DoSomething();
} // r.Dispose() is called
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
checked and unchecked Statements
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Statements
Basic Input/Output Statements

string v1 = “some value”;


MyObject v2 = new MyObject();
Console.WriteLine(“First is {0}, second is {1}”,
v1, v2);
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Operators
Overview
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Operators
Precedence

Category Operators
Grouping: (x)
Member access: x.y
Method call: f(x)
Indexing: a[x]
Post-increment: x++
Primary
Post-decrement: x—
Constructor call: new
Type retrieval: typeof
Arithmetic check on: checked
Arithmetic check off: unchecked
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Operators
Precedence

Category Operators
Positive value of: +
Negative value of: -
Not: !
Unary Bitwise complement: ~
Pre-increment: ++x
Post-decrement: --x
Type cast: (T)x

Multiply: *
Multiplicative Divide: /
Division remainder: %
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Operators
Precedence

Category Operators
Add: +
Additive
Subtract: -
Shift bits left: <<
Shift
Shift bits right: >>

Less than: <


Greater than: >
Less than or equal to: <=
Relational
Greater than or equal to: >=
Type equality/compatibility: is
Type conversion: as
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Operators
Precedence

Category Operators
Equals: ==
Equality
Not equals: !=
Bitwise AND &

Bitwise XOR ^

Bitwise OR |

Logical AND &&

Logical OR ||
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Operators
Precedence

Category Operators
Ternary conditional ?:

Assignment =, *=, /=, %=, +=, -=, <<=, >>=,


&=, ^=, |=
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Operators
Associativity
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Using Visual Studio.NET
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Using Visual
Studio.NET
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
Using Visual Studio.NET
BMS INSTITUTE OF TECHNOLOGY AND MANAGEMENT
More Resources

You might also like