.Net Programming with C#

Slides:



Advertisements
Similar presentations
2. C# Language Fundamentals
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Neal Stublen C# Data Types Built-in Types  Integer Types byte, sbyte, short, ushort, int, uint, long, ulong  Floating Point Types.
C#: Data Types Based on slides by Joe Hummel. 2 UCN Technology: Computer Science Content: “.NET is designed around the CTS, or Common Type System.
Data Types and Expressions
Types and Variables. Computer Programming 2 C++ in one page!
1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
1 9/8/08CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
CS150 Introduction to Computer Science 1
Variables and constants Applications of Computer Programming in Earth Sciences Instructor: Dr. Cheng-Chien LiuCheng-Chien Liu Department of Earth Sciences.
Integer, Floating-Point, Text Data, Variables, Literals Svetlin Nakov Telerik Corporation
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.
3. Declaring Value-Type Variables
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
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.
CPS120: Introduction to Computer Science
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Primitive Data Types and Variables Integer, Floating-Point, Text Data, Variables, Literals SoftUni Team Technical Trainers Software University
Java Simple Types CSIS 3701: Advanced Object Oriented Programming.
Primitive Variables.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
Java Overview. Comments in a Java Program Comments can be single line comments like C++ Example: //This is a Java Comment Comments can be spread over.
Telerik Software Academy Telerik School Academy Integer, Floating-Point, Text Data, Variables,
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 2 Variables.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
1.2 Primitive Data Types and Variables
CPS120: Introduction to Computer Science Variables and Constants.
Chapter One Lesson Three DATA TYPES ©
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 06 – Java Datatypes Webpage:
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Computer Programs CS 1400 Dennis A. Fairclough Version 1.1 CS 1400 Dennis A. Fairclough Version 1.1.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Fundamentals 2.
Basic Introduction to C#
Chapter 2 Variables.
Variable Declarations
Chapter 4 – Fundamental Data Types
Data Types, Arithmetic Operations
EPSII 59:006 Spring 2004.
Understand Computer Storage and Data Types
Chapter 3: Understanding C# Language Fundamentals
.Net Programming with C#
Computers & Programming Languages
Chapter 2 Variables.
C++ Data Types Data Type
Chapter 2: Java Fundamentals
Variables Data Types Lab 0B
Data Types Imran Rashid CTO at ManiWeber Technologies.
Chapter 2: Java Fundamentals
ECE 103 Engineering Programming Chapter 8 Data Types and Constants
Unit 3: Variables in Java
B065: PROGRAMMING Variables 2.
Chapter 2 Variables.
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Presentation transcript:

.Net Programming with C# Haiming Chen Department of Computer Science Ningbo University Fall Semester , 2016-2017 Course 106F22A01

Data type in C# Type Description Range/Precision Example bool ulong Boolean type true, false bool val1 = true; bool val2 = false; short 16-bit signed integer –32,768...32,767 short val = 12; int 32-bit signed integer –2,147,483,648...2,147,483,647 int val = 12; long 64-bit signed integer –9,223,372,036,854,775,808 ...9,223,372,036,854,775,807 long val1 = 12; long val2 = 34L; byte 8-bit unsigned integer 0...255 byte val1 = 12; byte val2 = 34U; ushort 16-bit unsigned integer 0...65,535 ushort val1 = 12; ushort val2 = 34U; uint 32-bit unsigned integer 0...4,294,967,295 uint val1 = 12; uint val2 = 34U; ulong 64-bit unsigned integer 0...18,446,744,073,709,551,615 ulong val1 = 12; ulong val2 = 34U; ulong val3 = 56L; ulong val4 = 78UL;

Data type in C# Type Description Range/Precision Example float char decimal Precise decimal type 1.0 × 10−28 至 7.9 × 1028,28-figure precision decimal val = 1.23M; float Single-precision float type 1.5 × 10−45 至 3.4 × 1038,7-figure precision float val = 1.23F; double Double-precision float type 5.0 × 10−324 至 1.7 × 10308,15-figure precision double val1 = 1.23; double val2 = 4.56D; char A character letters, digits, and special characters, like ‘#’, ‘@’, ‘$’, which has a Unicode char val1 = 'h'; char val2 = ‘\’’; char val3 = ‘\\’ char val4 = ‘\uhhhh’; https://unicode-table.com/en/ string A series of characters string s= "Hello";

String Operation Join Extract character or substring string str=“aaa”+”bbb”; string str=“aaa”+’1’; string str=“aaa”+1; string str=“aaa”+1.23M; Extract character or substring char c=str[0]; string subStr= str. Substring(0,3); // Substring(4); int index = str. IndexOf(“b”); // LastIndexOf(“b”); 1 2 3 4 5 6 a b 1

String Operation Compare str1.CompareTo (str2); // -1 means str1<str2 // 1 means str1>str2 // 0 means str1==str2 str1. Equals (str2); Remove leading and trailing white-space characters str1.Trim();

String Operation Convert string to number Convert number to string int num = int.Parse(“123”); float num = float.Parse(“123.456”); Convert number to string string str = num.ToString(); string str = string. Format (“{0}”, num);

Array type [,…] array_name = new type [n,…]; int [] intArray = new int [3]; short [] shortArray = new short []{1,2,3} string [] strArray = {“Ning”, “ ”, “bo”}; string [] strArray; // declaration strArray = new string [3]; // initialization strArray = {“Ning”, “ ”, “bo”}; //set value, error strArray[0] = “Ning”; strArray[1] = “ “; strArray[2] = “bo”; Ning bo

Array Operation GetLength(); GetValue(index); SetValue (newValue, index) CopyTo(newArray, fromIndex); Convert string to string array str.Split(‘separator character’); Convert string array to string string.Join (“separator string”, string_array)

Example Change the string “Ningbo Zhejiang China” to “Ningbo, Zhejiang, China” string str= “Ningbo Zhejiang China”; int indexSpace=str.IndexOf(“ “); str[indexSpace]=‘,’; // error Note: Each character in a string cannot be changed separately.

Overview Data types in C# Define variables Define constants Value types (char, int, long, short, float, double,…) String Array Define variables Declare Initialize Define constants const float _pi = 3.1415169F Do them at the same time