Learning C#. What is C# A new object oriented language  Syntax based on C Similar to C++ and Java  Used to write.NET software Software that targets.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Exception Handling The purpose of exception handling is to permit the program to catch and handle errors rather than letting the error occur and suffer.
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
C#.NET C# language. C# A modern, general-purpose object-oriented language Part of the.NET family of languages ECMA standard Based on C and C++
Trey Mack James Moore Osa Osar-Emokpae
History  We first begin with Java which was released in 1995 by Sun Microsystems  Initially Java was 100% interpreted at runtime and was very slow 
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
CS/ENGRD 2110 SPRING 2013 Lecture 2: Introduction to Java 1.
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
Differences between C# and C++ Dr. Catherine Stringfellow Dr. Stewart Carpenter.
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
Object Oriented Programming
Assertions Program correctness. Assertions Java statement – enables you to assert an assumption about your program. – An assertion contains a Boolean.
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
Tutorial C#. PLAN I. Introduction II. Example of C# program :Hello World III. How to use C# language GUI elements Primitives Types Expressions and operators.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Programming in C#. I. Introduction C# (or C-Sharp) is a programming language. C# is used to write software that runs on the.NET Framework. Although C#
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Applied Computing Technology Laboratory QuickStart C# Learning to Program in C# Amy Roberge & John Linehan November 7, 2005.
ILM Proprietary and Confidential -
C# Programming Fundamentals Control Flow Jim Warren, COMPSCI 280 S Enterprise Software Development.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Applications Development
1 Introduction to C# Programming Console applications No visual components Only text output Two types MS-DOS prompt - Used in Windows 95/98/ME Command.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Chapters 2 & 3. .NET Software development model that allows applications created in disparate programming languages to communicate Universal data access.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
INTRODUCTION CHAPTER #1 Visual Basic.NET. VB.Net General features It is an object oriented language  In the past VB had objects but focus was not placed.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
Exception Handling How to handle the runtime errors.
Overview CNS 3260 C#.NET Software Development. 2.NET Framework Began in 2000 Developed in three years (2000 to 2003) Operating System Hardware.NET Framework.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
C# Fundamentals An Introduction. Before we begin How to get started writing C# – Quick tour of the dev. Environment – The current C# version is 5.0 –
Exception and Exception Handling. Exception An abnormal event that is likely to happen during program is execution Computer could run out of memory Calling.
1 Statements © University of Linz, Institute for System Software, 2004 published under the Microsoft Curriculum License.
Object Oriented Programming Lecture 2: BallWorld.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Information and Computer Sciences University of Hawaii, Manoa
A variable is a name for a value stored in memory.
Internet and Java Foundations, Programming and Practice
University of Central Florida COP 3330 Object Oriented Programming
Chapter 3 Assignment Statement
CS360 Windows Programming
Introduction to C# AKEEL AHMED.
Tutorial C#.
null, true, and false are also reserved.
Advanced Programming Lecture 02: Introduction to C# Apps
Conditional Statements
Introduction to Java Programming
An overview of Java, Data types and variables
Chapter 1: Computer Systems
Units with – James tedder
Units with – James tedder
Chapter 3 – Introduction to C# Programming
Focus of the Course Object-Oriented Software Development
.NET Base Type (CTS Data Type) Managed Extensions for C++ Keyword
Presentation transcript:

Learning C#

What is C# A new object oriented language  Syntax based on C Similar to C++ and Java  Used to write.NET software Software that targets the.NET Framework is called managed code  C# gains much from the.NET Framework Internet oriented platform JIT compilation Automatic memory management Security, type-safety Framework Class Library

C#: Rich Software Development Provides access to the.NET Framework  Great language for targeting.NET  Access the features of the framework For example, the FCL Create Web-based apps, GUI, apps, etc. Offers access to the underlying OS  Full access to Windows (or host OS)  Enables creation of rich applications Object oriented  Create component based applications  Gain the benefits of OO design, with no compromises

Defining the.NET Framework The.NET Framework is  A software development environment  A runtime engine for Managed Code  A platform designed for Internet-Distributed software The.NET Framework is an exciting new computing platform

Hello World a-la C# using System.Windows.Forms; using System.Drawing; class MyForm:Form{ public static void Main(){ Application.Run(new MyForm()); } protected override void OnPaint(PaintEventArgs e){ e.Graphics.DrawString("Hello World!", new Font("Arial", 35), Brushes.Blue, 10, 100); } HelloGUI.cs c:\> csc /target:winexe HelloGui.cs

Types of Applications Managed code is packaged as Assemblies The three kinds of assemblies that you can create with C# are the following.  Console applications  GUI applications  Libraries of Types Libraries of Types are especially important because  Applications are going to consist of more and more reusable component code  Web Forms and Web Service applications are published as libraries

Creating a Console Application using System; class App{ public static void Main(String[] args){ try{ Int32 iterations = Convert.ToInt32(args[0]); if(iterations > 138){ throw new Exception(); } Decimal lastNum = 1; Decimal secondToLastNum = 0; while(iterations-- > 0){ Decimal newNum = lastNum+secondToLastNum; Console.WriteLine(newNum); secondToLastNum = lastNum; lastNum = newNum; } }catch{ Console.WriteLine( "Usage: Rabbits [Fib Index]\n"+ "\t[Fib Index] < 139"); } Rabbits.cs c:\> csc Rabbits.cs

Creating a GUI Application using System; using System.Drawing; using System.Windows.Forms; class App{ public static void Main(){ Application.Run(new TribbleForm()); } class TribbleForm:Form{ TextBox generationsTextBox; ListBox fibList; //... Tribbles.cs c:\> csc /target:winexe Tribbles.cs

Creating a Code Library using System; public class Fib{ Decimal current; Decimal last; public Fib(){ current = 1; last = 0; } private Fib(Decimal last, Decimal secondToLast){ current = last+secondToLast; this.last = last; } public Fib GetNext(){ return new Fib(current, last); } public Decimal Value{ get{return current;} } FibObj.cs c:\> csc /target:library FibObj.cs

Code that Uses a Code Library using System; class App{ public static void Main(){ Int32 index = 50; Fib obj = new Fib(); do{ Console.WriteLine(obj.Value); obj = obj.GetNext(); }while(index-- != 0); } FibTest.cs c:\> csc /r:FibOjb.dll FibTest.cs

Language Concepts Syntax based on C/C++  Case-sensitive  White space means nothing  Semicolons ( ; ) to terminate statements  Code blocks use curly braces ( {} ) Some features  Can create methods with a variable number of arguments  Parameters are passed by value (by default) Can create methods that take parameters by reference Can create methods with out-only parameters  Operator overloading and type converters  Type-safety and code verification Object oriented, code is structured using the class keyword

Primitive Types Signed Numeric Primitive Types  Int32, Int16, Int64, SByte, Double, Single, Decimal Unsigned Numeric Primitive Types  UInt32, UInt16, UInt64, Byte Other Primitives  Boolean, String, Char, Object Primitive Types are FCL Types  C# Aliases the primitives  Example: Int32 == int

Conditional Statements C# uses if C# uses switch if(y == x){ Console.WriteLine("y equals x"); }else{ Console.WriteLine("y does not equal x"); } switch(x){ case 2: Console.WriteLine("x equals 2"); break; default: Console.WriteLine("x does not equal 2"); break; }

C# Loops… C# uses for C# uses while for(index = 0;index<100;index++){ Console.Write(index); Console.Write("\t"); } index = 10; while(index != 0){ Console.WriteLine(index); index--; }

C# Loops (continued) C# uses do - while C# uses foreach index = 0; do{ Console.WriteLine("Happens at least once"); }while(index < 0); Int32[] myArray = new Int32[]{10, 20, 30, 40}; foreach(Int32 i in myArray){ Console.WriteLine(i); }

C# Error Handling C# uses try - catch try{ Int32 index = 10; while(index-- != 0){ Console.WriteLine(100/index); } }catch(DivideByZeroException){ Console.WriteLine( “Caught division by zero exception"); } Console.WriteLine( “Caught; code keeps running");

C# Assured Cleanup 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  The Framework Class Library (FCL)  Third party libraries using System; using System.IO; class App{ public static void Main(String[] args){ StreamReader reader = new StreamReader(args[0]); Console.WriteLine(reader.ReadToEnd()); } TypeFile.cs

Demo C#Pad.cs

Learning C#

Demo MDLView

Demo Visual Studio.Net

Demo TerraViewer