02 LearningCSharp
02 LearningCSharp
What is C#
Object oriented
Create component based applications
Gain the benefits of OO design, with no compromises
Defining the .NET Framework
class MyForm:Form{
public static void Main(){
Application.Run(new MyForm());
}
class App{
public static void Main(){
Application.Run(new TribbleForm());
}
}
class TribbleForm:Form{
TextBox generationsTextBox;
ListBox fibList;
// ...
index = 10;
while(index != 0){
Console.WriteLine(index);
index--;
}
C# Loops (continued)
C# uses do-while
index = 0;
do{
Console.WriteLine("Happens at least once");
}while(index < 0);
C# uses foreach
C# uses try-finally
try{
// Perhaps an exception is thrown or
// return statement is hit
return;
}finally{
Console.WriteLine(
"Code in finally always runs");
}
Using Types
You will often use types from
TheFramework Class Library (FCL)
Third party libraries
TypeFile.cs
using System;
using System.IO;
class App{
public static void Main(String[] args){
StreamReader reader =
new StreamReader(args[0]);
Console.WriteLine(reader.ReadToEnd());
}
}
Demo C#Pad.cs
Learning C#
Demo
MDLView
Demo Visual Studio.Net
Demo TerraViewer