C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.

Slides:



Advertisements
Similar presentations
Introduction to programming in java. Input and output to screen with Java program Structure of Java programs Statements Conditional statements.
Advertisements

Computer and Programming
Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
IT151: Introduction to Programming
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Your First Java Program: HelloWorld.java
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Datalogi A 1: 8/9. Book: Cay Horstmann: Big Java or Java Consepts.
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
C# Programming: From Problem Analysis to Program Design1 2 Your First C# Program C# Programming: From Problem Analysis to Program Design 2 nd Edition.
Introduction to Computing and Programming
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
C# Programming: From Problem Analysis to Program Design1 2 Your First C# Program.
Computer Science A 1: 3/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
“Introduction to Programming With Java”
Computer and Programming File I/O File Input/Output Author: Chaiporn Jaikaeo, Jittat Fakcharoenphol Edited by Supaporn Erjongmanee Lecture 13.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Hello AP Computer Science!. What are some of the things that you have used computers for?
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
CompSci 42.1Intro to Java Anatomy of a Class & Terminology Running and Modifying a Program.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
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.
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#
Intro to More Controls in C#. C# Demonstration We already touched on labels and buttons Ad-hoc demo of controls – Textboxes Multiline – Checkbox – Radiobutton.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Introduction to C++ Version 1.1. Topics C++ Structure Primitive Data Types I/O Casting Strings Control Flow.
Lecture 3: Getting Started & Input / Output (I/O) “TRON” Copyright 1982 (Walt Disney Productions)
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.
Anatomy.1 Anatomy of a Class & Terminology. Anatomy.2 The Plan Go over MoveTest.java from Big Java Basic coding conventions Review with GreeterTest.java.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
CSC 142 B 1 CSC 142 Java objects: a first view [Reading: chapters 1 & 2]
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Advanced Programming LOOP. 2 while Repetition Structure Repetition Structure –An action is to be repeated Continues while statement is true Ends when.
C++ LANGUAGE TUTORIAL LESSON 1 –WRITING YOUR FIRST PROGRAM.
 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.
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects 1. How is a class different from an object?
CSC 110 – Intro to Computing - Programming
1 Structure of Simple C++ Program Chapter 1 09/09/13.
Lecture 01 C# Basics Dr. Eng. Ibrahim El-Nahry. 2 Welcome to CSC-102 Instructor:Dr.Eng. Ibrahim El-nahry Office:Building Com.Bldg, Room 13 Office Phone:……………….
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Introduction to programming in java
C# Programming: From Problem Analysis to Program Design
Computer Programming Your First Java Program: HelloWorld.java.
Using the Console.
Chapter 1.2 Introduction to C++ Programming
USING ECLIPSE TO CREATE HELLO WORLD
C# and the .NET Framework
Getting Started with C.
Intro to Java.
C# Programming: From Problem Analysis to Program Design
Advanced Programming Lecture 02: Introduction to C# Apps
Tonga Institute of Higher Education
Java Intro.
Chapter 3 – Introduction to C# Programming
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Loops CGS3416 Spring 2019 Lecture 7.
IS 135 Business Programming
Presentation transcript:

C# B 1 CSC 298 Writing a C# application

C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void Main() { System.Console.WriteLine("Hello, world") ; } comment class definition class method use the System.Console class to write some text to the console every C# statement ends with a semi colon ;

C# B 3 Code organization  In C# (as in Java), no stand alone function  Code is written inside of blocks {} that are class definitions  public class HelloWorld { // my code is here … }  for now always write public class. More on this later  Good habits from Java (not required in C#)  Name the file that contains the definition of the public class HelloWorld: HelloWorld.cs  Write only one public class per C# file

C# B 4 Comments  Ignored by the computer. Essential for the reader.  2 types of comments: // and /* */  Everything between // and the end of the line is a comment  Everything between /* and */ is a comment. It can be used on several lines. You can't nest these comments (/* blabla /* blabla */ blabla */ gives an error)  Examples  // this is a comment  /* this is a comment that can be written on several lines */  Also XML comments /// (see VS.NET doc)

C# B 5 The Main method  An application always start executing with the Main method (note the capital M)  The Main method must be static  It can be of type void or return an int  It can take no arguments or an array of strings  It can be of any visibility (public, private…) public static int Main() static void Main(String[] args) // default to private

C# B 6 Console Input/Output in C#  Console: a class to access I/O functionalities for the console (=DOS window)  In: input stream, Out: output stream  important static methods: Write, WriteLine, ReadLine  Console is available in the namespace System Console.Write ("Enter your name: "); String name = Console.ReadLine(); Console.WriteLine("Welcome " + name);

C# B 7 System.Windows.Forms  A namespace that contains many classes to build graphical user interfaces  We will see many examples  Here is a simple example MessageBox.Show("Hello, world!", "Message");

C# B 8 The using statement  Define a shortcut to write the names of classes of the FCL in our programs.  using System.Windows.Forms means:  get access to all of the classes in the namespace System.Windows.Forms  In the program, to access the class System.Windows.Forms.MessageBox just type MessageBox

C# B 9 Formatting output  To concatenate strings (=sequence of characters), use +  Write("Hello, " + "World") prints Hello, World  Write(""+1+2) is not the same as Write(1+2). Why?  For tabs and newlines, use '\t' and '\n'  Write("Hello\tWorld") prints Hello World  Write("Hello\nWorld") prints Hello World  See later for other ways