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.

Slides:



Advertisements
Similar presentations
What Is Java? The name Java is a trademark of Sun Microsystems
Advertisements

Basic Java Constructs and Data Types – Nuts and Bolts
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Chapter 1 Chapter 2 Chapter 3 Code Gone Wrong Random 5 pt 5 pt 5 pt
Windows form application using System.Windows.Forms; using System.Drawing; class MyForm:Form{ public static void Main(){ Application.Run(new.
CSE 341, Winter Type Systems Terms to learn about types: –Type –Type system –Statically typed language –Dynamically typed language –Type error –Strongly.
Lab#1 (14/3/1431h) Introduction To java programming cs425
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Road Map Introduction to object oriented programming. Classes
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
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.
Java Programming, 3e Concepts and Techniques Chapter 3 Manipulating Data Using Methods.
CS102 Data Types in Java CS 102 Java’s Central Casting.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
Introduction to Java CS 331. Introduction Present the syntax of Java Introduce the Java API Demonstrate how to build –stand-alone Java programs –Java.
1 Chapter 3 Programs and Packages. 2 Java Virtual Machine (JVM) Java programs execute on the JVM. The JVM is a virtual rather than a physical machine,
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Hello, world! Dissect HelloWorld.java Compile it Run it.
Tahir Nawaz Visual Programming C# Week 2. What is C#? C# (pronounced "C sharp") is an object- oriented language that is used to build applications for.
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
Computer Science and Software Engineering University of Wisconsin - Platteville 7. Inheritance and Polymorphism Yan Shi CS/SE 2630 Lecture Notes.
Object Oriented Programming
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to .NET Framework
UNIVERSITI TENAGA NASIONAL “Generates Professionals” CHAPTER 4 : Part 2 INTRODUCTION TO SOFTWARE DEVELOPMENT: PROGRAMMING & LANGUAGES.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 62 – Manipulating Data Using Methods – Day 1.
Computing with C# and the.NET Framework Chapter 1 An Introduction to Computing with C# ©2003, 2011 Art Gittleman.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
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#
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
POS 406 Java Technology And Beginning Java Code
Java Programming, Second Edition Chapter One Creating Your First Java Program.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
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.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Methods in Java. Program Modules in Java  Java programs are written by combining new methods and classes with predefined methods in the Java Application.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
 Programming - the process of creating computer programs.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Access Modifiers Control which classes use a feature Only class-level variables may be controlled by access modifiers Modifiers 1. public 2. protected.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
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 –
Terms: Software  Set of instructions  aka programs  Operating System:  Special software whose job it is to translateinstructions into hardware instructions.
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Introduction to Object Oriented
Lecture 1b- Introduction
The need for Programming Languages
Internet and Java Foundations, Programming and Practice
C# and the .NET Framework
Programming Language Concepts (CIS 635)
Namespaces, Scopes, Access privileges
Java Programming: From Problem Analysis to Program Design, 4e
Tutorial C#.
5 Variables, Data Types.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Java’s Central Casting
Chap 1. Getting Started Objectives
Chap 4. Programming Fundamentals
Presentation transcript:

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

I. Introduction C# (or C-Sharp) is a new programming language. C# is used to write software that runs on the.NET Framework. Although C# is not the only language that you can use to target the.NET Framework, C# is one of the most popular because of its simplified C- based syntax.

I. Introduction In brief, C# (unlike C++, PERL, COBOL, Pascal, etc.) is a language that targets one and only one platform. This platform is the.NET Framework. However, the.NET Framework itself is a computing platform that is designed to be hosted by any operating system. At the time of this writing the.NET Framework runs on Windows operating systems, and I know of two other major OSs for which a version of the.NET Framework is being developed.

I. Introduction So you can see that although C# is designed to target only the Framework, the Framework itself is flexible enough to run your C# programs on many types of systems.

I. Introduction The relationship between C# and the.NET Framework is somewhat unique. First, C# is not the only language that can be used to write.NET Framework applications (called Managed Applications). Second,.NET or managed, applications run in native machine- language and are not interpreted. Third, C# or managed applications do not run in a sandbox.

II. Hello World 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); } Figure 1-1

II. Hello World The source code in Figure 1 ‑ 1 displays the text "Hello World!" in a window. (The C# version of a command line hello-world application would be a one-liner). As you can see from the code, C# has a C-based syntax, but with objects like C++ or Java. Every function in C# is a method of a type. In this example, the MyForm class is defined to derive its functionality from the Form class (part of the.NET Framework Class Library). In addition it defines two new methods, Main() and OnPaint(). All C# (or.NET) applications must have a static method named Main() defined to be the entry point of the application.

II. Hello World The static Main() method can be defined in any class in the application, so long as its name is “Main” and it is declared to be static. The OnPaint() method is an override of a virtual method on the Form class. It is called when the window needs to paint itself. This sample uses this method to draw the text "Hello World!". Most of the code in Figure 1 ‑ 1 will be covered in detail throughout this text. Don’t worry too much about the parts that don’t make sense right now. However, I would take the time to look the code over, perhaps build and run it, and get a feel for the sample.

III. C# Language I am going to take you on a quick tour of the different types of binaries you can build with C#. I use the term binaries, because one of the three is a non-executable binary with types (classes, interfaces, etc.) defined in it that can be used by other managed executables. In fact there is a special name for a compiled binary in the.NET world, and it is Assembly. All managed executable files are assemblies. All libraries of classes and interfaces are packaged as assemblies (often with a.dll file extension). The concept of an assembly is important, because this is what your managed code must reference when it is using a type defined elsewhere. 1. GUI elements

III. C# Language The three kinds of assemblies that you can create with C# are the following. · Console applications · GUI applications · Libraries of Types The important thing to remember about assemblies is that they are not source-code. They are compiled binaries that can be executed directly. 1. GUI elements

III. C# Language 2.Primitives Types The table shown later in this section shows the types in the Framework Class Library that are treated as primitive types by C#. Primitive types are special because the C# language will allow direct assignment, math operations, and comparison of primitive types. For example, the following line of code would be legal in C# because both variables are of type Int32 x = x + y; Meanwhile, the very same line of code would not be legal of the x and y variables were of some non-primitive type such as Form or FileStream.

III. C# Language 2.Primitives Types One other interesting point about the primitive types in C# is that the C# language provides Aliases for the type names. For example, whether you declare a variable of type Int32 or of type int, you are always really declaring an Int32 variable. Choosing which name to use in your source code is a matter of style. The most important thing is that you recognize that the FCL name for a primitive type and the alias name for a primitive type both refer to the same underlying type.

III. C# Language 2.Primitives Types C# has a String type, rather than requiring that strings be represented as an array of Char variables like C or C++. · C# has a Boolean type, and it is not valid to use a numerical type where a Boolean expression is required. C# also includes two keywords for indicating true and false. · Since C# uses types defined in the FCL as its primitive types, C#’s primitive types are Object ’s just like all other types in the system. Said another way, all C# primitive types are derived from Object, and as objects do object-like things such-as implement instance methods, etc.

III. C# Language 3.Expressions and operators Expressions are an integral part of programming, and C# treats expressions much the same as many languages. Operators such as +, *, and / are used to manipulate or affect the data in variables, and operators have precedence. And as is common, operator precedence can be modified using parenthesis. Expressions like the following are common in programming, and are also common with C#. Int32 x = 10*(y+z); C# is a very type safe language, however, and expressions are strongly typed. For example, the preceding line of code is an expression of type Int32. The compiler will automatically convert between numeric primitive types, so long as no data-loss occurs in the conversion. However, some conversions that are common in languages like C or C++ are illegal in C#.

III. C# Language 3.Expressions and operators An example of such an illegal type conversion in an expression is the conversion from an Int32 or some other numeric type to a Boolean type. The following code would be valid in C, but is an error in C#, because a Boolean expression is expected, and an Int32 expression is provided. Int32 x = 10; while(x--) DoSomething(); The operators in the following table can be used in C# expressions.

III. C# Language 3.Expressions and operators