SlideShare a Scribd company logo
1
C # and .Net Technologies
Advantages of .NET over the other languages
The .Net Framework offers a number of advantages to developers.
Below are few advantages of .Net Framework:
1. Consistent programming model : With .Net accessing data with a C# and VB.Net very similar
apart from slight syntactial differeneces. Both the programs need to import the System.Data
namespace, both programs establish connection with database and both programs run a
query and display the data.
2. Direct Support for Security : .Net framework enables the developer and the system
administrator to specify method level security.
3. Simplified Development efforts: The .Net Framework simplifies debugging with support for
Runtime diagnostics.
4. Easy application deployment and Maintenance : The .Net Framework makes easy to deploy
applicaitons.The .Net Framework handles the details of locating and loads the components.
5. Assemblies : Assembly is elementary unit in a framework application. It performs various
functions in programming with the .Net Frame work. Every computer that has the .Net
Framework installed with have the Global Assembly Cache.
Overview of .NET binaries
 .NET binaries take the extension of .dll
 .NET binaries do not contain platform-specific instructions, but rather platform-
agnostic intermediate language (IL) and type metadata.
 When a *.dll or *.exe has been created using a .NET-aware compiler, the resulting
module is bundled into an assembly.
Note: An assembly is a collection of types and resources that are built to work together and form a logical unit
of functionality
2
Intermediate Language
 CIL(Common Intermediate Language) is a language that sits above any particular
platform-specific instruction set. Regardless of which .NET-aware language you
choose, the associated compiler emits CIL instructions
 For example, C# compiler emits CIL, not platform-specific instructions
Benefits of CIL:
 One benefit is language integration. .NET-aware compiler produces nearly identical
CIL instructions. Therefore, all languages are able to interact within a well-defined
binary arena
 .NET allows you to build applications using your language of choice
Metadata
 In addition to CIL instructions, a .NET assembly contains full, complete, and accurate
metadata
 Metadata describes each and every type (class, structure, enumeration, and so forth)
defined in the binary, as well as the members of each type (properties, methods, events, and
so on).
 It is always the job of the compiler to generate latest metadata.
.NET Namespaces
 C# language does not come with a language-specific code library. Rather, C# developers
leverage the language-neutral .NET libraries.
 A namespace is a grouping of related types contained in an assembly. For example, the
System.IO namespace contains file I/O related types, the System.Data namespace defines
basic database types, and so on
 Any language targeting the .NET runtime makes use of the same namespaces and same
types.
Accessing a Namespace Programmatically
// Explicitly list the namespaces used by this file.
using System;
using System.Drawing;
class MyApp {
public void DisplayLogo() {
// Create a 20_20 pixel bitmap.
Bitmap companyLogo = new Bitmap(20, 20);
...
} }
3
Building block of .NET
Common Language runtime, common type system, common Language Specification
Note: In the world of .NET, “type” is simply a generic term used to refer to a member from the set {class,
structure, interface, enumeration, delegate}
Common Type System (CTS)
 CTS is a formal specification that documents how types must be defined in order to be
hosted by the CLR
 Five types defined by the CTS:
1. CTS Class Types
2. CTS Structure Types
3. CTS Interface Types
4. CTS Enumeration Types
5. CTS Delegate Types
Common Language Specification
 Different languages express the same programming constructs in unique, language specific
terms, for example, in c# for Concatenation we use ‘+’ operator, while in VB.NET we use ‘&’.
Yet, respective compilers (csc.exe or vbc.exe, in this case) emit a similar set
of CIL(Common Intermediate Language) instructions.
 The Common Language Specification (CLS) is a set of rules that describe in vivid detail the
 minimal and complete set of features a given .NET-aware compiler must support to produce
code that can be hosted by the CLR.
 The CLS is ultimately a set of rules that compiler builders must conform to, if they intend
their products to function seamlessly within the .NET universe.
Common Language Runtime
 Term runtime can be understood as a collection of external services that are required to
execute a given compiled unit of code.
 .NET runtime provides a single well-defined runtime layer that is shared by all languages and
platforms that are .NET-aware
 The runtime engine is responsible for a number of tasks:
 Firstly, it is the entity in charge of resolving the location of an assembly and finding the
requested type within the binary by reading the contained metadata.
 The CLR then lays out the type in memory, compiles the associated CIL into platform-
specific instructions, performs any necessary security checks, and then executes the
code in question.
Note: An assembler is a program that takes basic computer instructions and converts them into a pattern of bits that the
computer's processor can use to perform its basic operations. Some people call these instructions assembler language and
others use the term assembly language.
Eg: L 8,3000
Means: Load the contents of memory location 3000 into Register 8.
4
C# Fundamentals
C# classes & Objects
Defining Classes and Creating Objects
A class is a definition for a user-defined type.
An object is simply a term describing a given instance of a particular class in memory.
Eg:
using System;
class HelloClass {
public static int Main(string[] args) {
// You can declare and create a new object in a single line...
HelloClass c1 = new HelloClass();
// ...or break declaration and creation into two lines.
HelloClass c2;
c2 = new HelloClass();
...
} }
Default Values of Class Member Variables
 Boolean types are set to false.
 Numeric data is set to 0 (or 0.0 in the case of floating-point data types).
 String types are set to null.
 Char types are set to '0'.
 Reference types are set to null.
String Formatting
The C# string keyword is a shorthand notation of the System.String type, which provides a
number of members you would expect from such a utility class
5
Types
There are basically 5 types in c#.
1. Classes
2. Structures
3. Interfaces
4. Enumerations
5. Delegates
Structures
A struct type is a value type that is typically used to encapsulate small groups of related
variables, such as the coordinates of a rectangle or the characteristics of an item in an
inventory
public struct Book
{
public decimal price;
public string title;
public string author;
}
The objects of a strcut can be created by using the new operator as follows.
book myBooks = new book();
The individual members of a struct can be accessed by using the dot (.) operator as showing
below.
myBooks.title= “who cares”;
myBooks.author = “Walking Stone”;
Interface
 An interface contains only the signatures of methods, properties, events or indexers.
 A class or struct that implements the interface must implement the members of the
interface that are specified in the interface definition
interface ISampleInterface {
void SampleMethod();
}
class ImplementationClass : ISampleInterface {
// Explicit interface member implementation:
void ISampleInterface.SampleMethod() {
// Method implementation.
}
Public static void Main() {
// Declare an interface instance.
ISampleInterface obj = new ImplementationClass();
// Call the member.
obj.SampleMethod(); } }
6
Enumerations
The enum keyword is used to declare an enumeration, a distinct type that consists of a set
of named constants called the enumerator list.
By default, the first enumerator has the value 0, and the value of each successive
enumerator is increased by 1. For example, in the following enumeration, Sat is 0, Sun is 1,
Mon is 2, and so forth.
enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};
Enumerators can use initializers to override the default values, as shown in the following
example.
enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri};
Delegates
 A delegate is a type that represents references to methods with a particular parameter
list and return type
 When you instantiate a delegate, you can associate its instance with any method with a
compatible signature and return type. You can invoke (or call) the method through the
delegate instance
public delegate int PerformCalculation(int x, int y);
Delegates have the following properties:
 Delegates are like C++ function pointers but are type safe.
 Delegates allow methods to be passed as parameters.
 Delegates can be used to define callback methods.
 Delegates can be chained together; for example, multiple methods can be called on
a single event.
Scopes
The scope of a name is the region of program text within which it is possible to refer to the entity
declared by the name without qualification of the name
 The scope of a namespace member declared by a namespace-member-declaration with no
enclosing namespace-declaration is the entire program text.
 The scope of a parameter declared in a constructor-declaration is the constructor-initializer
and block of that constructor-declaration.
 The scope of a local variable declared in a local-variable-declaration is the block in which the
declaration occurs.
 The scope of a local variable declared in a switch-block of a switch statement is the switch-
block.
 The scope of a local variable declared in a for-initializer of a for statement is the for-
initializer, the for-condition, the for-iterator, and the contained statement of the for
statement.
 The scope of a parameter declared in a method-declaration is the method-body of that
method-declaration.
 The scope of a member declared by a struct-member-declaration is the struct-body in which
the declaration occurs.
 The scope of a member declared by an enum-member-declaration is the enum-body in
which the declaration occurs.
7
Constants
 Constants are immutable(unchanging over time) values which are known at compile
time and do not change for the life of the program.
 Constants are declared with the const modifier.
 Only the C# built-in types(eg, int, float, string etc) may be declared as const.
Eg:
class Calendar
{
const int months = 12, weeks = 52, days = 365;
}
C# iteration
The following keywords are used in iteration statements:
 do
 for
 foreach
 while
foreach: The foreach statement repeats a group of embedded statements for each element in an
array or an object collection
Control Flow
 if
 switch
 break
 continue
Operators
 Arithmetic Operators( +, -, *, /, %, ++, --)
 Relational Operators (==, !=, >, <, >=, <= )
 Logical Operators (&&, ||, !)
 Bitwise Operators (&, |, ^, ~, <<, >>)
 Assignment Operators (==, +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |=)
 Misc Operators (sizeof(), typeof(), &-returns address of variable, *-pointer, ?: , is, as)
Arrays
C# arrays can be divided into 4 categories:
1. Single-dimensional arrays
2. Multidimensional arrays or rectangular arrays
3. Jagged arrays
4. Mixed arrays.
8
1. Single-dimensional arrays:
int[] myNum = new int[3] {1, 3, 5};
string[] strArray = new string[5] { "Mahesh", "Mike", "Raj", "Praveen", "Dinesh" };
2. Multidimensional arrays or rectangular arrays:
A multi-dimensional array, also known as a rectangular array is an array with more than one
dimension. The form of a multi-dimensional array is a matrix.
int[,] numbers = new int[3, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 } };
string[,] names = new string[2, 2] { { "Rosy", "Amy" }, { "Peter", "Albert" } };
We can also initialize as :
int[,] numbers = new int[3, 2];
numbers[0, 0] = 1;
numbers[1, 0] = 2;
3. Jagged arrays
Jagged arrays are arrays of arrays. The elements of a jagged array are other arrays.
For example, the following code snippet declares a jagged array that has three items of an
array.
int[ ][ ] intJaggedArray = new int[3][ ];
Initializing jagged arrays:
intJaggedArray[0] = new int[2];
intJaggedArray[1] = new int[4];
intJaggedArray[2] = new int[6];
We can also initialize as:
intJaggedArray[0] = new int[2]{2, 12};
intJaggedArray[1] = new int[4]{4, 14, 24, 34};
intJaggedArray[2] = new int[6] {6, 16, 26, 36, 46, 56 };
Accessing Jagged arrays:
Console.Write(intJaggedArray3[0][0]);
4. Mixed arrays
Mixed arrays are a combination of multi-dimension arrays and jagged arrays. The mixed
arrays type is removed from .NET 4.0.
9
Strings
 A string is an object of type String whose value is text.
 Internally, the text is stored as a sequential read-only collection of Char objects.
 There is no null-terminating character at the end of a C# string;
string name=”David”;
String escape sequences
t - Horizontal tab
v - Vertical tab
 - Backslash
' - Single quote
" - Double quote
n - New line
Custom Namespaces
Custom namespace allows us to define our own namespaces and import them
into another program or application.
Eg:
// addtionlib.cs
using System;
namespace MyAddition
{
class addit{
………
}
}
myprogram.cs
using System;
using MyAddition //importing user-defined namespace
namespace myprogram
{
…….
}
}

More Related Content

What's hot

C# Constructors
C# ConstructorsC# Constructors
C# Constructors
Prem Kumar Badri
 
Operators
OperatorsOperators
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
Ritika Sharma
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data typesManisha Keim
 
11 constructors in derived classes
11 constructors in derived classes11 constructors in derived classes
11 constructors in derived classes
Docent Education
 
C Programming: Structure and Union
C Programming: Structure and UnionC Programming: Structure and Union
C Programming: Structure and Union
Selvaraj Seerangan
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
Prem Kumar Badri
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
VB net lab.pdf
VB net lab.pdfVB net lab.pdf
VB net lab.pdf
Prof. Dr. K. Adisesha
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
Dhrumil Patel
 
Data Types In C
Data Types In CData Types In C
Data Types In C
Simplilearn
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#Literals,variables,datatype in C#
Literals,variables,datatype in C#
Prasanna Kumar SM
 
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
Docent Education
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
Dr.Neeraj Kumar Pandey
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
topu93
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
Ngeam Soly
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 

What's hot (20)

C# Constructors
C# ConstructorsC# Constructors
C# Constructors
 
Operators
OperatorsOperators
Operators
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Concept of c data types
Concept of c data typesConcept of c data types
Concept of c data types
 
11 constructors in derived classes
11 constructors in derived classes11 constructors in derived classes
11 constructors in derived classes
 
C Programming: Structure and Union
C Programming: Structure and UnionC Programming: Structure and Union
C Programming: Structure and Union
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
VB net lab.pdf
VB net lab.pdfVB net lab.pdf
VB net lab.pdf
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Data Types In C
Data Types In CData Types In C
Data Types In C
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Literals,variables,datatype in C#
Literals,variables,datatype in C#Literals,variables,datatype in C#
Literals,variables,datatype in C#
 
Functions in c
Functions in cFunctions in c
Functions in c
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
 
C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#C# lecture 2: Literals , Variables and Data Types in C#
C# lecture 2: Literals , Variables and Data Types in C#
 
Presentation on c structures
Presentation on c   structures Presentation on c   structures
Presentation on c structures
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 

Similar to C# Unit 1 notes

Csharp
CsharpCsharp
Csharp
vinayabburi
 
C# note
C# noteC# note
Dotnet interview qa
Dotnet interview qaDotnet interview qa
Dotnet interview qaabcxyzqaz
 
Session2 (3)
Session2 (3)Session2 (3)
Session2 (3)
DrUjwala1
 
.Net framework
.Net framework.Net framework
.Net frameworkRaghu nath
 
Dot net
Dot netDot net
Dot net
public
 
Namespaces in C#
Namespaces in C#Namespaces in C#
Namespaces in C#
yogita kachve
 
.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligeti.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligeti
Naveen Kumar Veligeti
 
Srgoc dotnet_new
Srgoc dotnet_newSrgoc dotnet_new
Srgoc dotnet_new
Gaurav Singh
 

Similar to C# Unit 1 notes (20)

Csharp
CsharpCsharp
Csharp
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
 
C# note
C# noteC# note
C# note
 
Dotnet interview qa
Dotnet interview qaDotnet interview qa
Dotnet interview qa
 
Session2 (3)
Session2 (3)Session2 (3)
Session2 (3)
 
.Net framework
.Net framework.Net framework
.Net framework
 
Dot net
Dot netDot net
Dot net
 
C Course Material0209
C Course Material0209C Course Material0209
C Course Material0209
 
C sharp
C sharpC sharp
C sharp
 
Namespaces in C#
Namespaces in C#Namespaces in C#
Namespaces in C#
 
Intro.net
Intro.netIntro.net
Intro.net
 
Dotnet basics
Dotnet basicsDotnet basics
Dotnet basics
 
C#ppt
C#pptC#ppt
C#ppt
 
csharp.docx
csharp.docxcsharp.docx
csharp.docx
 
C Sharp Jn
C Sharp JnC Sharp Jn
C Sharp Jn
 
C Sharp Jn
C Sharp JnC Sharp Jn
C Sharp Jn
 
.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligeti.Net framework components by naveen kumar veligeti
.Net framework components by naveen kumar veligeti
 
Introduction to Visual Studio.NET
Introduction to Visual Studio.NETIntroduction to Visual Studio.NET
Introduction to Visual Studio.NET
 
.Net slid
.Net slid.Net slid
.Net slid
 
Srgoc dotnet_new
Srgoc dotnet_newSrgoc dotnet_new
Srgoc dotnet_new
 

More from Sudarshan Dhondaley

Storage Area Networks Unit 1 Notes
Storage Area Networks Unit 1 NotesStorage Area Networks Unit 1 Notes
Storage Area Networks Unit 1 Notes
Sudarshan Dhondaley
 
Storage Area Networks Unit 4 Notes
Storage Area Networks Unit 4 NotesStorage Area Networks Unit 4 Notes
Storage Area Networks Unit 4 Notes
Sudarshan Dhondaley
 
Storage Area Networks Unit 3 Notes
Storage Area Networks Unit 3 NotesStorage Area Networks Unit 3 Notes
Storage Area Networks Unit 3 Notes
Sudarshan Dhondaley
 
Storage Area Networks Unit 2 Notes
Storage Area Networks Unit 2 NotesStorage Area Networks Unit 2 Notes
Storage Area Networks Unit 2 Notes
Sudarshan Dhondaley
 
C# Unit5 Notes
C# Unit5 NotesC# Unit5 Notes
C# Unit5 Notes
Sudarshan Dhondaley
 
Architectural Styles and Case Studies, Software architecture ,unit–2
Architectural Styles and Case Studies, Software architecture ,unit–2Architectural Styles and Case Studies, Software architecture ,unit–2
Architectural Styles and Case Studies, Software architecture ,unit–2
Sudarshan Dhondaley
 
Designing and documenting software architecture unit 5
Designing and documenting software architecture unit 5Designing and documenting software architecture unit 5
Designing and documenting software architecture unit 5Sudarshan Dhondaley
 
Software architecture Unit 1 notes
Software architecture Unit 1 notesSoftware architecture Unit 1 notes
Software architecture Unit 1 notesSudarshan Dhondaley
 

More from Sudarshan Dhondaley (8)

Storage Area Networks Unit 1 Notes
Storage Area Networks Unit 1 NotesStorage Area Networks Unit 1 Notes
Storage Area Networks Unit 1 Notes
 
Storage Area Networks Unit 4 Notes
Storage Area Networks Unit 4 NotesStorage Area Networks Unit 4 Notes
Storage Area Networks Unit 4 Notes
 
Storage Area Networks Unit 3 Notes
Storage Area Networks Unit 3 NotesStorage Area Networks Unit 3 Notes
Storage Area Networks Unit 3 Notes
 
Storage Area Networks Unit 2 Notes
Storage Area Networks Unit 2 NotesStorage Area Networks Unit 2 Notes
Storage Area Networks Unit 2 Notes
 
C# Unit5 Notes
C# Unit5 NotesC# Unit5 Notes
C# Unit5 Notes
 
Architectural Styles and Case Studies, Software architecture ,unit–2
Architectural Styles and Case Studies, Software architecture ,unit–2Architectural Styles and Case Studies, Software architecture ,unit–2
Architectural Styles and Case Studies, Software architecture ,unit–2
 
Designing and documenting software architecture unit 5
Designing and documenting software architecture unit 5Designing and documenting software architecture unit 5
Designing and documenting software architecture unit 5
 
Software architecture Unit 1 notes
Software architecture Unit 1 notesSoftware architecture Unit 1 notes
Software architecture Unit 1 notes
 

Recently uploaded

Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 

Recently uploaded (20)

Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 

C# Unit 1 notes

  • 1. 1 C # and .Net Technologies Advantages of .NET over the other languages The .Net Framework offers a number of advantages to developers. Below are few advantages of .Net Framework: 1. Consistent programming model : With .Net accessing data with a C# and VB.Net very similar apart from slight syntactial differeneces. Both the programs need to import the System.Data namespace, both programs establish connection with database and both programs run a query and display the data. 2. Direct Support for Security : .Net framework enables the developer and the system administrator to specify method level security. 3. Simplified Development efforts: The .Net Framework simplifies debugging with support for Runtime diagnostics. 4. Easy application deployment and Maintenance : The .Net Framework makes easy to deploy applicaitons.The .Net Framework handles the details of locating and loads the components. 5. Assemblies : Assembly is elementary unit in a framework application. It performs various functions in programming with the .Net Frame work. Every computer that has the .Net Framework installed with have the Global Assembly Cache. Overview of .NET binaries  .NET binaries take the extension of .dll  .NET binaries do not contain platform-specific instructions, but rather platform- agnostic intermediate language (IL) and type metadata.  When a *.dll or *.exe has been created using a .NET-aware compiler, the resulting module is bundled into an assembly. Note: An assembly is a collection of types and resources that are built to work together and form a logical unit of functionality
  • 2. 2 Intermediate Language  CIL(Common Intermediate Language) is a language that sits above any particular platform-specific instruction set. Regardless of which .NET-aware language you choose, the associated compiler emits CIL instructions  For example, C# compiler emits CIL, not platform-specific instructions Benefits of CIL:  One benefit is language integration. .NET-aware compiler produces nearly identical CIL instructions. Therefore, all languages are able to interact within a well-defined binary arena  .NET allows you to build applications using your language of choice Metadata  In addition to CIL instructions, a .NET assembly contains full, complete, and accurate metadata  Metadata describes each and every type (class, structure, enumeration, and so forth) defined in the binary, as well as the members of each type (properties, methods, events, and so on).  It is always the job of the compiler to generate latest metadata. .NET Namespaces  C# language does not come with a language-specific code library. Rather, C# developers leverage the language-neutral .NET libraries.  A namespace is a grouping of related types contained in an assembly. For example, the System.IO namespace contains file I/O related types, the System.Data namespace defines basic database types, and so on  Any language targeting the .NET runtime makes use of the same namespaces and same types. Accessing a Namespace Programmatically // Explicitly list the namespaces used by this file. using System; using System.Drawing; class MyApp { public void DisplayLogo() { // Create a 20_20 pixel bitmap. Bitmap companyLogo = new Bitmap(20, 20); ... } }
  • 3. 3 Building block of .NET Common Language runtime, common type system, common Language Specification Note: In the world of .NET, “type” is simply a generic term used to refer to a member from the set {class, structure, interface, enumeration, delegate} Common Type System (CTS)  CTS is a formal specification that documents how types must be defined in order to be hosted by the CLR  Five types defined by the CTS: 1. CTS Class Types 2. CTS Structure Types 3. CTS Interface Types 4. CTS Enumeration Types 5. CTS Delegate Types Common Language Specification  Different languages express the same programming constructs in unique, language specific terms, for example, in c# for Concatenation we use ‘+’ operator, while in VB.NET we use ‘&’. Yet, respective compilers (csc.exe or vbc.exe, in this case) emit a similar set of CIL(Common Intermediate Language) instructions.  The Common Language Specification (CLS) is a set of rules that describe in vivid detail the  minimal and complete set of features a given .NET-aware compiler must support to produce code that can be hosted by the CLR.  The CLS is ultimately a set of rules that compiler builders must conform to, if they intend their products to function seamlessly within the .NET universe. Common Language Runtime  Term runtime can be understood as a collection of external services that are required to execute a given compiled unit of code.  .NET runtime provides a single well-defined runtime layer that is shared by all languages and platforms that are .NET-aware  The runtime engine is responsible for a number of tasks:  Firstly, it is the entity in charge of resolving the location of an assembly and finding the requested type within the binary by reading the contained metadata.  The CLR then lays out the type in memory, compiles the associated CIL into platform- specific instructions, performs any necessary security checks, and then executes the code in question. Note: An assembler is a program that takes basic computer instructions and converts them into a pattern of bits that the computer's processor can use to perform its basic operations. Some people call these instructions assembler language and others use the term assembly language. Eg: L 8,3000 Means: Load the contents of memory location 3000 into Register 8.
  • 4. 4 C# Fundamentals C# classes & Objects Defining Classes and Creating Objects A class is a definition for a user-defined type. An object is simply a term describing a given instance of a particular class in memory. Eg: using System; class HelloClass { public static int Main(string[] args) { // You can declare and create a new object in a single line... HelloClass c1 = new HelloClass(); // ...or break declaration and creation into two lines. HelloClass c2; c2 = new HelloClass(); ... } } Default Values of Class Member Variables  Boolean types are set to false.  Numeric data is set to 0 (or 0.0 in the case of floating-point data types).  String types are set to null.  Char types are set to '0'.  Reference types are set to null. String Formatting The C# string keyword is a shorthand notation of the System.String type, which provides a number of members you would expect from such a utility class
  • 5. 5 Types There are basically 5 types in c#. 1. Classes 2. Structures 3. Interfaces 4. Enumerations 5. Delegates Structures A struct type is a value type that is typically used to encapsulate small groups of related variables, such as the coordinates of a rectangle or the characteristics of an item in an inventory public struct Book { public decimal price; public string title; public string author; } The objects of a strcut can be created by using the new operator as follows. book myBooks = new book(); The individual members of a struct can be accessed by using the dot (.) operator as showing below. myBooks.title= “who cares”; myBooks.author = “Walking Stone”; Interface  An interface contains only the signatures of methods, properties, events or indexers.  A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition interface ISampleInterface { void SampleMethod(); } class ImplementationClass : ISampleInterface { // Explicit interface member implementation: void ISampleInterface.SampleMethod() { // Method implementation. } Public static void Main() { // Declare an interface instance. ISampleInterface obj = new ImplementationClass(); // Call the member. obj.SampleMethod(); } }
  • 6. 6 Enumerations The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list. By default, the first enumerator has the value 0, and the value of each successive enumerator is increased by 1. For example, in the following enumeration, Sat is 0, Sun is 1, Mon is 2, and so forth. enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri}; Enumerators can use initializers to override the default values, as shown in the following example. enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; Delegates  A delegate is a type that represents references to methods with a particular parameter list and return type  When you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type. You can invoke (or call) the method through the delegate instance public delegate int PerformCalculation(int x, int y); Delegates have the following properties:  Delegates are like C++ function pointers but are type safe.  Delegates allow methods to be passed as parameters.  Delegates can be used to define callback methods.  Delegates can be chained together; for example, multiple methods can be called on a single event. Scopes The scope of a name is the region of program text within which it is possible to refer to the entity declared by the name without qualification of the name  The scope of a namespace member declared by a namespace-member-declaration with no enclosing namespace-declaration is the entire program text.  The scope of a parameter declared in a constructor-declaration is the constructor-initializer and block of that constructor-declaration.  The scope of a local variable declared in a local-variable-declaration is the block in which the declaration occurs.  The scope of a local variable declared in a switch-block of a switch statement is the switch- block.  The scope of a local variable declared in a for-initializer of a for statement is the for- initializer, the for-condition, the for-iterator, and the contained statement of the for statement.  The scope of a parameter declared in a method-declaration is the method-body of that method-declaration.  The scope of a member declared by a struct-member-declaration is the struct-body in which the declaration occurs.  The scope of a member declared by an enum-member-declaration is the enum-body in which the declaration occurs.
  • 7. 7 Constants  Constants are immutable(unchanging over time) values which are known at compile time and do not change for the life of the program.  Constants are declared with the const modifier.  Only the C# built-in types(eg, int, float, string etc) may be declared as const. Eg: class Calendar { const int months = 12, weeks = 52, days = 365; } C# iteration The following keywords are used in iteration statements:  do  for  foreach  while foreach: The foreach statement repeats a group of embedded statements for each element in an array or an object collection Control Flow  if  switch  break  continue Operators  Arithmetic Operators( +, -, *, /, %, ++, --)  Relational Operators (==, !=, >, <, >=, <= )  Logical Operators (&&, ||, !)  Bitwise Operators (&, |, ^, ~, <<, >>)  Assignment Operators (==, +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |=)  Misc Operators (sizeof(), typeof(), &-returns address of variable, *-pointer, ?: , is, as) Arrays C# arrays can be divided into 4 categories: 1. Single-dimensional arrays 2. Multidimensional arrays or rectangular arrays 3. Jagged arrays 4. Mixed arrays.
  • 8. 8 1. Single-dimensional arrays: int[] myNum = new int[3] {1, 3, 5}; string[] strArray = new string[5] { "Mahesh", "Mike", "Raj", "Praveen", "Dinesh" }; 2. Multidimensional arrays or rectangular arrays: A multi-dimensional array, also known as a rectangular array is an array with more than one dimension. The form of a multi-dimensional array is a matrix. int[,] numbers = new int[3, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 } }; string[,] names = new string[2, 2] { { "Rosy", "Amy" }, { "Peter", "Albert" } }; We can also initialize as : int[,] numbers = new int[3, 2]; numbers[0, 0] = 1; numbers[1, 0] = 2; 3. Jagged arrays Jagged arrays are arrays of arrays. The elements of a jagged array are other arrays. For example, the following code snippet declares a jagged array that has three items of an array. int[ ][ ] intJaggedArray = new int[3][ ]; Initializing jagged arrays: intJaggedArray[0] = new int[2]; intJaggedArray[1] = new int[4]; intJaggedArray[2] = new int[6]; We can also initialize as: intJaggedArray[0] = new int[2]{2, 12}; intJaggedArray[1] = new int[4]{4, 14, 24, 34}; intJaggedArray[2] = new int[6] {6, 16, 26, 36, 46, 56 }; Accessing Jagged arrays: Console.Write(intJaggedArray3[0][0]); 4. Mixed arrays Mixed arrays are a combination of multi-dimension arrays and jagged arrays. The mixed arrays type is removed from .NET 4.0.
  • 9. 9 Strings  A string is an object of type String whose value is text.  Internally, the text is stored as a sequential read-only collection of Char objects.  There is no null-terminating character at the end of a C# string; string name=”David”; String escape sequences t - Horizontal tab v - Vertical tab - Backslash ' - Single quote " - Double quote n - New line Custom Namespaces Custom namespace allows us to define our own namespaces and import them into another program or application. Eg: // addtionlib.cs using System; namespace MyAddition { class addit{ ……… } } myprogram.cs using System; using MyAddition //importing user-defined namespace namespace myprogram { ……. } }