Basic Introduction to C#

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms The C Programming Language.
Advertisements

C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
Neal Stublen C# Data Types Built-in Types  Integer Types byte, sbyte, short, ushort, int, uint, long, ulong  Floating Point Types.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
CS 225 Java Review. Java Applications A java application consists of one or more classes –Each class is in a separate file –Use the main class to start.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
String Escape Sequences
Java versus C# An introduction to C# and Visual Studio.
Programming in C# Language Overview
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.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
Distributed Systems (236351) Tutorial 1 - Getting Started with Visual Studio C#.NET.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
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.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Chapter 2: Using Data.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Introduction to C++ // Program description #include directives int main() { constant declarations variable declarations executable statements return.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
Primitive data Week 3. Lecture outcomes Primitive data – integer – double – string – char – Float – Long – boolean Declaration Initialisation Assignments.
Basic Java Syntax COMP 401, Spring 2014 Lecture 2 1/14/2014.
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
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.
Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
C# - variablesBjørk Busch1 Variables Basic types (also defined as classes with methods) : Integer-types Int, long, byte, sbyte, short, ushort, uint, ulong.
ITK 168 – More Variables 10/13/05. Another example of using instance variables and constants  Go through SimpleBot  Modify SimpleBot to “teleport”
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Introduction to C# Anders Hejlsberg Distinguished Engineer Developer Division Microsoft Corporation.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Chapter 2 Variables.
Selenium WebDriver Web Test Tool Training
Computing with C# and the .NET Framework
Basic Java Syntax The Java language will be described by working through its features: variable types and expressions selection and iteration classes exceptions.
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 3: Understanding C# Language Fundamentals
CS360 Windows Programming
.NET and .NET Core 5.2 Type Operations Pan Wuming 2016.
Dr Shahriar Bijani Winter 2017
Escape Sequences What if we wanted to print the quote character?
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I UTPA – Fall 2012 This set of slides is revised from lecture slides.
Starting JavaProgramming
2.1 Parts of a C++ Program.
An Introduction to Java – Part I, language basics
An overview of Java, Data types and variables
Chapter 2: Basic Elements of Java
Introduction to Primitive Data types
Data Types Imran Rashid CTO at ManiWeber Technologies.
C Programming Getting started Variables Basic C operators Conditionals
Chapter 2: Introduction to C++.
Module 2 Variables, Assignment, and Data Types
Visual Programming COMP-315
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Module 2 Variables, Data Types and Arithmetic
Chapter 2 Variables.
Loops CGS3416 Spring 2019 Lecture 7.
Introduction to Primitive Data types
Presentation transcript:

Basic Introduction to C#

Why C# ? Native support for Namespaces Versioning Attribute-driven development Power of C with ease of Microsoft Visual Basic® Minimal learning curve for everybody Much cleaner than C++ More structured than Visual Basic More powerful than Java

C# – The Big Ideas A component oriented language The first “component oriented” language in the C/C++ family In OOP a component is: A reusable program that can be combined with other components in the same system to form an application. They can be deployed on different servers and communicate with each other Enables one-stop programming No header files, IDL, etc. Can be embedded in web pages

C# Overview Object oriented Everything belongs to a class no global scope Complete C# program: using System; namespace ConsoleTest { class Class1 static void Main(string[] args) }

C# Program Structure Namespaces Type declarations Members Organization Contain types and other namespaces Type declarations Classes, structs, interfaces, enums, and delegates Members Constants, fields, methods, properties, events, operators, constructors, destructors Organization No header files, code written “in-line”

Simple Types Integer Types Floating Point Types Exact Numeric Type byte, sbyte (8bit), short, ushort (16bit) int, uint (32bit), long, ulong (64bit) Floating Point Types float (precision of 7 digits) double (precision of 15–16 digits) Exact Numeric Type decimal (28 significant digits) Character Types char (single character) string (rich functionality, by-reference type) Boolean Type bool (distinct type, not interchangeable with int)

Arrays Built on .NET System.Array class Declared with type and shape, but no bounds int [ ] SingleDim; int [ , ] TwoDim; int [ ][ ] Jagged; Created using new with bounds or initializers SingleDim = new int[20]; TwoDim = new int[,]{{1,2,3},{4,5,6}}; Jagged = new int[1][ ]; Jagged[0] = new int[ ]{1,2,3};

Statements and Comments Case sensitive (myVar != MyVar) Statement delimiter is semicolon ; Block delimiter is curly brackets { } Single line comment is // Block comment is /* */ Save block comments for debugging!

Data All data types derived from System.Object Declarations: datatype varname; datatype varname = initvalue; C# does not automatically initialize local variables (but will warn you)!

Value Data Types Directly contain their data: int (numbers) long (really big numbers) bool (true or false) char (unicode characters) float (7-digit floating point numbers) string (multiple characters together)

Data Manipulation = assignment + addition - subtraction * multiplication / division % modulus ++ increment by one -- decrement by one

strings Immutable sequence of Unicode characters (char) Creation: string s = “Bob”; string s = new String(“Bob”); Backslash is an escape: Newline: “\n” Tab: “\t”

string/int conversions string to numbers: int i = int.Parse(“12345”); float f = float.Parse(“123.45”); Numbers to strings: string msg = “Your number is ” + 123; string msg = “It costs ” + string.Format(“{0:C}”, 1.23);

Arrays (page 21 of quickstart handout) Derived from System.Array Use square brackets [ ] Zero-based Static size Initialization: int [ ] nums; int [ ] nums = new int[3]; // 3 items int [ ] nums = new int[ ] {10, 20, 30};

Arrays Final Multidimensional // 3 rows, 2 columns int [ , ] myMultiIntArray = new int[3,2] for(int r=0; r<3; r++) { myMultiIntArray[r][0] = 0; myMultiIntArray[r][1] = 0; }

Conditional Operators == equals != not equals < less than <= less than or equal > greater than >= greater than or equal && and || or

If, Case Statements if (expression) { statements; } else if else switch (i) { case 1: statements; break; case 2: default: }

Loops while (condition) { statements; } for (initialize-statement; condition; increment-statement); { statements; } while (condition) { statements; } Note: can include break and continue statements

Classes, Members and Methods Everything is encapsulated in a class Can have: member data member methods Class clsName { modifier dataType varName; modifier returnType methodName (params) statements; return returnVal; }

Hello World namespace Sample { using System; public class HelloWorld { public HelloWorld() { } public static int Main(string[] args) { Console.WriteLine("Hello World!"); return 0; } } } Constructor

Another Example using System; namespace ConsoleTest { public class Class1 public string FirstName = "Kay"; public string LastName = "Connelly"; public string GetWholeName() return FirstName + " " + LastName; } static void Main(string[] args) Class1 myClassInstance = new Class1(); Console.WriteLine("Name: " + myClassInstance.GetWholeName()); while(true) ;

Summary C# builds on the .NET Framework component model New language with familiar structure Easy to adopt for developers of C, C++, Java, and Visual Basic applications Fully object oriented Optimized for the .NET Framework

ASP .Net and C# Easily combined and ready to be used in WebPages. Powerful Fast Most of the works are done without getting stuck in low level programming and driver fixing and …

An ASP.Net Simple Start

End of The C#