Getting Started with C# 1 SWE 344 Internet Protocols & Client Server Programming.

Slides:



Advertisements
Similar presentations
C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Advertisements

Neal Stublen C# Data Types Built-in Types  Integer Types byte, sbyte, short, ushort, int, uint, long, ulong  Floating Point Types.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Getting Started with C#.  Name: Ahmed Galib Reza   Lab: Ubiquitous Computing Lab  Nationality: Bangladeshi  Education:
CMT Programming Software Applications
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
CHAPTER 2 BASIC ELEMENTS OF C++. In this chapter, you will:  Become familiar with the basic components of a C++ program, including functions, special.
C# Tutorial From C++ to C#. Some useful links Msdn C# us/library/kx37x362.aspxhttp://msdn.microsoft.com/en- us/library/kx37x362.aspx.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Introduction to Classes and Objects (Through Ch 5) Dr. John P. Abraham Professor UTPA.
1. 2 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Decisions { class.
Chapter 2: Introducing Data Types and Operators.  Know Java’s primitive types  Use literals  Initialize variables  Know the scope rules of variables.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
1 Course Lectures Available on line:
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
Input & Output: Console
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Computing with C# and the.NET Framework Chapter 1 An Introduction to Computing with C# ©2003, 2011 Art Gittleman.
2440: 211 Interactive Web Programming Expressions & Operators.
CSCI 3328 Object Oriented Programming in C# Chapter 3: Introduction to Classes and Objects UTPA – Fall
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
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_OOP Lecture #2: Computer Hardware/Software; Variables, C# Data Types, and IO.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Chapter 2: Using Data.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
C++ Programming: Basic Elements of C++.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Chapter 2: Introduction to C++. Outline Basic “Hello World!!” Variables Data Types Illustration.
1 Chapter 2: Java Fundamentals cont’d Spring Lory Al Moakar.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
1.2 Primitive Data Types and Variables
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
Lecture 2 Computational Constructs Variables & Expressions Boolean Logic Conditionals: if & switch Branching & Looping Data Types & Type Conversion Structs,
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Chapter 6 JavaScript: Introduction to Scripting
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Lecture 2 Data Types Richard Gesick.
Computing Fundamentals
Chapter 2: Problem Solving Using C++
C# and the .NET Framework
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2.
2.1 Parts of a C++ Program.
WEB PROGRAMMING JavaScript.
Chapter 2: Basic Elements of Java
elementary programming
Chapter 2: Introduction to C++.
The important features of OOP related to C#:
Module 2 Variables, Assignment, and Data Types
Presentation transcript:

Getting Started with C# 1 SWE 344 Internet Protocols & Client Server Programming

Outlines: Understand the basic structure of a C# program. Obtain a basic familiarization of what a "Namespace" is. Obtain a basic understanding of what a Class is. Learn what a Main method does. Learn how to obtain command-line input. Learn about console input/output (I/O). 2

Basics of.NET The Common Language Runtime (CLR) environment 3

C# Program structure  C# program has 4 primary elements: Namespace declaration Class Main method Program statement // Namespace Declaration using System; // Program start class class Class name { // Main begins program execution. static void Main() { Program statements; } } 4

C# Program structure 5

// Namespace Declaration using System; // Program start class class WelcomeCSS { // Main begins program execution. static void Main(string[] args) { // Write to console Console.Write("Welcome to Hail University"); Console.WriteLine(“……. Welcome"); Console.WriteLine(“Computer Science and Software Engineering"); // Keep screen from going away Console.ReadLine(); } } A Simple C# Program Welcome to Hail University……Welcome Computer Science and Software Engineering 6

The Main method specifies its behavior with the Console.WriteLine(...) statement. Console is a class in the System namespace. WriteLine(...) is a method in the Console class. We use the ".", dot, operator to separate subordinate program elements. Note that we could also write this statement as System.Console.WriteLine(...). This follows the pattern "namespace.class.method. Observe that comments are marked with "//". These are single line comments, meaning that they are valid until the end-of-line. If you wish to span multiple lines with a comment, begin with "/*" and end with "*/". Everything in between is part of the comment. Comments are ignored when your program compiles. They are there to document what your program does. All statements end with a ";", semi-colon. Classes and methods begin with "{", left curly brace, and end with a "}", right curly brace. Any statements within and including "{" and "}" define a block. Blocks define scope (or lifetime and visibility) of program elements. Notes about the program: 7

Operators, Types, and Variables "Variables" are simply storage locations for data. You can place data into them and retrieve their contents as part of a C# expression. The interpretation of the data in a variable is controlled through "Types". The Boolean Type Boolean types are declared using the keyword, bool. They have two values: true or false. bool x= true; bool y= false; 8

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { bool x = true; bool y = false; Console.WriteLine(“The value of x = {0}", x); Console.WriteLine(" The value of y = {0}", y); Console.ReadLine(); } Example: Boolean Type The value of x = True The value of y = False 9

Integral Types Operators, Types, and Variables TypeSize (in bits)Range sbyte8-128 to 127 byte80 to 255 short to ushort160 to int to uint320 to long to ulong640 to char160 to

Floating Point and Decimal Types Operators, Types, and Variables Type Size (in bits) precisionRange float327 digits 1.5 x to 3.4 x double digits 5.0 x to 1.7 x decimal decimal places 1.0 x to 7.9 x

String Type A string is a sequence of text characters. We typically create a string with a string literal, enclosed in quotes: “Hail University”. Some characters aren't printable, but you still need to use them in strings. Therefore, C# has a special syntax where characters can be escaped to represent non-printable characters. Operators, Types, and Variables 12

Escape Sequence Meaning \'Single Quote \"Double Quote \\Backslash \0Null, not the same as the C# null value \aBell \bBackspace \fform Feed \nNewline \rCarriage Return \tHorizontal Tab \vVertical Tab String Type Operators, Types, and Variables 13

C# Operators These expressions are built by combining variables and operators together into statements. Operators, Types, and Variables Category (by precedence) Operator(s) Associativi ty Unary+ - ! ~ ++x --x left Multiplicative* / %left Additive+ -left Shift >left Relational = is asleft Equality== !=right Logical AND&left Logical XOR^left Logical OR|left Conditional AND&&left Conditional OR||left Assignment = *= /= %= += - = >= &= ^= |= => right 14

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { int x, y, result; float floatresult; x = 7; y = 5; result = x + y; Console.WriteLine("x+y: {0}", result); result = x - y; Console.WriteLine("x-y: {0}", result); Example: C# Binary Operators 15

result = x * y; Console.WriteLine("x*y: {0}", result); result = x / y; Console.WriteLine("x/y: {0}", result); floatresult = (float)x / (float)y; Console.WriteLine("x/y: {0}", floatresult); result = x % y; Console.WriteLine("x%y: {0}", result); result += x; Console.WriteLine("result+=x: {0}", result); Console.ReadLine(); } Example: C# Binary Operators x+y: 12 x-y: 2 x*y: 35 x/y: 1 x/y: 1.4 x%y: 2 result+=x: 9 16

The Array Type Operators, Types, and Variables Array data type can be thought of as a container that has a list of storage locations for a specified type. When declaring an Array, specify the type, name, dimensions, and size. An array is considered a reference type. Therefore, an array requests its memory using the new operator. Based on this, one of the formulas to declare an array is: DataType[] VariableName = new DataType[Number]; Alternatively, you can use the var keyword to create an array. The formula to use would be: var VariableName = new DataType[Number]; 17

The Array Type Operators, Types, and Variables long[] ShelfNumbers = new long[10]; string[] Titles = new string[10]; string[] Directors = new string[10]; int[] Lengths = new int[10]; string[] Ratings = new string[10]; double[] Prices = new double[10]; var Numbers = new double[5]; Numbers[0] = 12.44; Numbers[1] = ; Numbers[2] = 6.28; Numbers[3] = ; Numbers[4] = ; DataType[] VariableName = new DataType[Number]; var VariableName = new DataType[Number]; 18

Example: The Array Type using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { int[] myInts = { 5, 10, 15 }; bool[][] myBools = new bool[2][]; myBools[0] = new bool[2]; myBools[1] = new bool[1]; double[,] myDoubles = new double[2, 2]; string[] myStrings = new string[3]; Console.WriteLine("myInts[0]: {0}, myInts[1]: {1}, 19

myInts[2]: {2}", myInts[0], myInts[1], myInts[2]); myBools[0][0] = true; myBools[0][1] = false; myBools[1][0] = true; Console.WriteLine("myBools[0][0]: {0}, myBools[1][0]: {1}", myBools[0][0], myBools[1][0]); myDoubles[0, 0] = 3.147; myDoubles[0, 1] = 7.157; myDoubles[1, 1] = 2.117; myDoubles[1, 0] = ; Console.WriteLine("myDoubles[0, 0]: {0}, myDoubles[1, 0]: {1}", myDoubles[0, 0], myDoubles[1, 0]); myStrings[0] = "Hail"; myStrings[1] = "is my"; myStrings[2] = "City"; Console.WriteLine("myStrings[0]: {0}, myStrings[1]: {1}, myStrings[2]: {2}", myStrings[0], myStrings[1], myStrings[2]); Console.ReadLine(); } 20

output: myInts[0]: 5, myInts[1]: 10, myInts[2]: 15 myBools[0][0]: true, myBools[1][0]: true myDoubles[0, 0]: 3.147, myDoubles[1, 0]: myStrings[0]: Hail, myStrings[1]: is my, myStrings[2]: City Example: The Array Type 21

22 END