Introduction To C
Introduction To C
Introduction to C# .NET
(Copyright © 2005-2011 Panayiotis Andreou)
Course contents
Overview of the Microsoft .NET Platform
• Lesson 1: Creating a new Windows Application
• Lesson 2: Introduction to Windows Forms
• Lesson 3: Adding Controls to a Form
• Lesson 4: Working with Controls
• Lesson 5: Creating MDI Applications
• Lesson 6: Introduction to Visual Basic
• Lesson 7: Building Mobile Applications
• Lesson 8: Deploying Applications
Developer Clients
Tools
ASP.NET Web
Databases Applications
Syntax
Comments
Single-line comments are marked with (//) at
the start
//These are single-line comments
in Pass by value
in
Pass by reference
out
Creating a new C#
Windows Application
Creating a new C# Project
Manage Database/Server
connections
Introduction to Windows
Forms
Forms in Solution Explorer
Maintaining two separate
files for the design and
code simplifies form
development.
Form/Class name
Categorized View
Alphabetical View
• A simple example
• Build a simple calculator
• Working with various controls
Practice: A simple example
Create a new form
To do this:
• Open Solution Explorer
• right click on your project (CSharpCrashCourse)
• Select AddAdd Windows Form
• Name the Form frmSimpleExample
• Add a TextBox and a Button to frmSimpleExample
• Button1.Text = TextBox1.Text;
Yes
private void txtNumber_Click(object sender, EventArgs e) {
//The sender is either txtFirstNumber or txtSecondNumber
System.Windows.Forms.TextBox txt = (TextBox)sender;
txt.Text = string.Empty;
}
Create 1 Label
• Change its (Name) Property to lblChoose
• Change its Size Property to 496, 24
• Change its Location Property to 8, 8
• Change its Text Property to
Choose your colors Gender City
Date Of Birth
Create 1 TextBox
• Change its (Name) Property to txtInfo
• Change its Multiline Property to True
• Change its Size Property to 496, 232
• Change its Location Property to 8, 224
• Change its Text Property to “”
summary += colors;
txtInfo.Text = summary;
VB.NET C#
C# to VB.NET comparison
C# VB
1. int i; 1. Dim i As Integer
2. int array[6]; 2. Dim array(5) As Integer
3. for(i=0;i<6;i++){…} 3. For i=0 To 5…Next I
4. while(cond){…} 4. While <cond>…End While
5. private void test()… 5. Private Sub test()…
6. private int test() … 6. Private Function test() As Integer …
7. return/break; 7. Exit …
Deploying Applications
Overview
1. Describing Assemblies
• Assemblies Overview
• Benefits of Strong-Named Assemblies
• Creating Strong-Named Assemblies
• Versioning Strong-Named Assemblies
• Using the Global Assembly Cache
3. Deploying Applications
Assemblies Overview
• Contains code, resources, and metadata
• Provides security, type, and reference scope
• Forms a deployment unit
• Versionable
• Side-by-side execution allows multiple installed
versions
• Global assembly cache allows assembly sharing
Benefits of Strong-Named Assemblies
• Guaranteed uniqueness
• No two strong names can be the same
• Protected version lineage
• Only legitimate assembly versions can be
loaded
• Enforced assembly integrity
• Assemblies are tested for unauthorized
modification before loading
Creating Strong-Named Assemblies
Requires identity, public key, and digital signature
Generating the public-private key pair
Create a .snk file
Modify AssemblyInfo.vb
<Assembly: AssemblyKeyFile("KeyFile.snk")>
Versioning Strong-Named Assemblies
When a client makes a binding request, the runtime
checks:
• The original binding information inside the
assembly
• Configuration files for version policy instructions
User’s Programs
Menu
Using the Editors
Registry
File types
User interface
Custom actions
Launch conditions
Creating Installation Components
EventLog
MessageQueue
PerformanceCounter
Service
ServiceProcess
Deploying the Application
Windows-based setup project
Copies all files
Registers components
Performs other installation tasks
Web setup project
Copies all files
Registers components
Creates a Web application
Practice
Using explorer, go to
%Solution Folder%\Setup1\Debug
Miscellaneous Topics
System.IO
System.Drawing
System.Diagnostics.Process
System.IO: File/Directory Operations
IO.File: File Operations
• Copy, Delete, Exists, Move, Replace, …
• Open(path, FileMode), Close,…
IO.FileMode: File mode when opening a file
• Append,Create,CreateNew,Open,OpenOrCreate,Truncate
IO.Stream
• FileStream, StreamReader/Writer, TextReader/Writer,…
System.Diagnostics.Process.Start("Calc.exe");
Microsoft® C#® .NET Crash Course