Date post: | 19-Feb-2017 |
Category: |
Education |
Author: | rasan-samarasinghe |
View: | 33 times |
Download: | 0 times |
Diploma in Information Technology Module IX: Programming with C#.NET
Diploma in Software EngineeringModule V: Windows Based Application Development in C#Rasan SamarasingheESOFT Computer Studies (pvt) Ltd.No 68/1, Main Street, Pallegama, Embilipitiya.
ContentsIntroduction to .NET Framework.NET Framework Platform ArchitectureMicrosoft Visual StudioC# LanguageC#, VS and .NET Framework VersionsYour First C# ApplicationPrinting StatementsComments in C#Common Type SystemValue Types and Reference TypeVariables Declaration in C#Type ConversionArithmetic OperatorsAssignment OperatorsComparison OperatorsLogical OperatorsIf StatementIf Else StatementIf Else if Else StatementNested If StatementSwitch StatementWhile LoopDo While Loop
For LoopArraysAccessing Arrays using foreach LoopTwo Dimensional ArraysClasses and Objects in C#Inheritance in C#Partial ClassesNamespacesWindows Forms ApplicationsUsing Buttons, Labels and Text BoxesDisplaying Message BoxesError Handling with Try Catch finallyUsing Radio ButtonsUsing Check BoxesUsing List BoxesCreating MenusCreating ToolStripsMDI FormsDatabase Application in C#Creating a Simple Database ApplicationSQL Insert / Update / Retrieving / DeleteSQL Command Execute MethodsData Sets
Introduction to .NET FrameworkThe .NET Framework is a software framework developed by Microsoft that runs primarily on Microsoft Windows.
It includes a large library and provides language interoperability across several programming languages.
Programs written for .NET Framework execute in a software environment known as CLR.
.NET Framework is intended to be used by most new applications created for the Windows platform.
.NET Framework Platform Architecture
Microsoft Visual StudioMicrosoft Visual Studio is an integrated development environment (IDE) from Microsoft
To develop Windows Forms or WPF applications, web sites, web applications, and web services
For Microsoft Windows, Windows Mobile, Windows CE, .NET Framework and Microsoft Silverlight.
C# LanguageC# is a general purpose, object oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg.
C# Language FeaturesBoolean Conditions Automatic Garbage Collection Standard Library Assembly Versioning Properties and Events Delegates and Events Management Easy-to-use Generics Indexers Conditional Compilation Simple Multithreading LINQ and Lambda Expressions Integration with Windows
C#, VS and .NET Framework VersionsC# VersionVisual Studio Version.NET Framework VersionC# 1.0Visual Studio .NET 2002.NET Framework 1.0C# 1.2Visual Studio .NET 2003.NET Framework 1.1C# 2.0Visual Studio 2005.NET Framework 2.0C# 3.0Visual Studio 2008Visual Studio 2010.NET Framework 2.0.NET Framework 3.0 .NET Framework 3.5C# 4.0Visual Studio 2010.NET Framework 4C# 5.0Visual Studio 2012Visual Studio 2013.NET Framework 4.5
Your First C# Applicationusing System;
namespace myspace{class FirstApp{ static void Main() { Console.WriteLine(Hello World!); }} }
Printing StatementsConsole.Write(Hello World!); //prints a text
Console.WriteLine(Hello World!); //printing end up with a new line
Console.Write(Hello \nWorld!); //line breaks
Console.Write(Hello {0}, Esoft); //variable displaying
Comments in C#Single line comments
// this is a single line comment
Multiline comments
/* this is a multilinecomment*/
Common Type System
Value Types and Reference TypePredefined Value Typessbyte-128 to 1278 bitsbyte0 to 2558 bitsshort-32,768 to 32,76716 bitsushort0 to 65,53516 bitsint-2,147,483,648 to 2,147,483,64732 bitsuint0 to 4,294,967,29532 bitslong-9,223,372,036,854,775,808 to 9,223,372,036,854,775,80764 bitsulong0 to 18,446,744,073,709,551,61564 bitschar16 bit Unicode character16 bitsfloat-3.4 x 1038 to + 3.4 x 103832 bitsdouble(+/-)5.0 x 10-324 to (+/-) 1.7 x 1030864 bitsdecimal(-7.9 x 1028 to 7.9 x 1028) / 100 to 28128 bitsboolHolds true or false1 bitPredefined Reference TypesstringRepresents a string of Unicode characters20+ bitsobjectRepresents a general purpose type8+ bits
Variable Declaration in C#Variable declarationtype variable_list;
Variable declaration and initializationtype variable_name = value;
Variables Declaration in C#int a, b, c; // declares three ints, a, b, and c.
int d = 3, e, f = 5; // declares three more ints, initializing d and f.
bool z = 5>2; // declares and initializes z.
double pi = 3.14159; // declares an approximation of pi.
char x = 'x'; // the variable x has the value 'x'.
Type ConversionImplicit Conversion No special syntax is required because the conversion is type safe and no data will be lost.
Explicit ConversionRequire a cast operator, and information might be lost in the conversion.
Conversions with helper classesTo convert between non-compatible types.
Implicit Conversion int x = 123;double y = x;
Explicit Conversiondouble y = 123.5;int x = (int)y;
Conversions with helper classesString x = "123";int y = Int.Parse(x);int z = Convert.ToInt32(x);
Arithmetic OperatorsOperatorDescriptionExample+AdditionX + Y will give 60-SubtractionX - Y will give -20*MultiplicationX * Y will give 800/DivisionY / X will give 2%ModulusY % X will give 0++IncrementY++ gives 41--DecrementY-- gives 39
X = 20, Y = 40
Assignment OperatorsOperatorExample=Z = X + Y will assign value of X + Y into Z+=Z += X is equivalent to Z = Z + X-=Z -= X is equivalent to Z = Z - X*=Z *= X is equivalent to Z = Z * X/=Z /= X is equivalent to Z = Z / X%=Z %= X is equivalent to Z = Z % X
Comparison OperatorsOperatorExample==(X == Y) is false.!=(X != Y) is true.>(X > Y) is false.=(X >= Y) is false.