Download presentation
Presentation is loading. Please wait.
Published byClifton Melton Modified over 6 years ago
1
MIS 324 -- Professor Sandvig MIS 324 Professor Sandvig
11/7/2018 C# Language MIS 324 Professor Sandvig
2
MIS 324 -- Professor Sandvig
11/7/2018 Overview Why learn C#? C# Basics Variables Data types Operators Control Structures
3
Why Learn C#? Modern language More user-friendly than older languages
Microsoft introduced in 2000 More user-friendly than older languages Managed code Memory allocation Garbage collection 100% object oriented Widely used
4
MIS 324 -- Professor Sandvig
11/7/2018 Variables C# strongly typed Similar to VB.NET PHP loosely typed Strongly typed: A variable accepts only one data type Type is explicitly declared when variable is declared
5
MIS 324 -- Professor Sandvig
11/7/2018 Variables Strongly Typed Advantage Less error prone Compiler more likely to catch programming errors Disadvantage More explicit data type conversions
6
Variables Variables are objects Have properties & methods
FName = FName.Replace(“S”,”P”);
7
MIS 324 -- Professor Sandvig
11/7/2018 Variables Commonly Used C# Data Types int 123 string “hi” double 1.23 bool true DateTime Jan. 8, :23:46 pm
8
Datatype Conversion Implicit Conversion Done when no data lost
9
Datatype Conversion Web Forms .NET MVC Lots of data type conversions
All data from web forms type string .NET MVC Data types defined in model Few datatype conversions needed
10
Variable Scope Control structures limit variable scope
Where variable is visible Visible in structure and children
11
Variable Scope Try to minimize scope Minimize complexity
“The road to Hell is paved with global variables” Steve McConnell Code Complete 2nd Ed.
12
Variable Scope Write code to minimize variable scope Good:
Control structures Classes Good:
13
MIS 324 -- Professor Sandvig
11/7/2018 Common C# Operators Operator Function Example = Assignment int a = 3; == equality if (a == 3) >= Greater or equal if (a >= 3) + Add int c = 3 + 4; Concatenate string s = “Hello ”+ “world”; ++ Increment by 1 i++; += Sum i += 3; s += “ and other planets”; ! Negate if(a != b) Control Structures example
14
MIS 324 -- Professor Sandvig
11/7/2018 Control Structures Syntax similar to C, JavaScript, PHP, Java, … Curley brackets for statement blocks if (condition) { //Statement block } else //statement block
15
MIS 324 -- Professor Sandvig
11/7/2018 Control Structures May omit brackets for single statements: if (condition) statement 1; else statement 2;
16
MIS 324 -- Professor Sandvig
11/7/2018 Control Structures Similar in all languages Syntax may be different if for foreach while
17
MIS 324 -- Professor Sandvig
11/7/2018 Control Structures 1. if else: if (condition) { //do something } else if (condition) else //do something else
18
MIS 324 -- Professor Sandvig
11/7/2018 Control Structures 2. for statement increments a counter variable may declare within statement for (int i = 0; i <= 10; i++) { ViewBag.message += “value of i:” + i + “<br>”; }
19
MIS 324 -- Professor Sandvig
11/7/2018 Control Structures 3. foreach loop iterate through collections arrays, controls, cookies, etc. int[] intArray = {3, 5, 7, 9}; foreach (int item in intArray) { ViewBag.message += “Item: “ + item + “<br>”; }
20
MIS 324 -- Professor Sandvig
11/7/2018 Control Structures 4. while loop int i = 0; while (i < 5) { i += 1; }
21
MIS 324 -- Professor Sandvig
11/7/2018 Summary C# modern object oriented programing language Relatively easy to use Managed code C-like syntax (similar to PHP, JavaScript, C, C++) Strongly typed Explicitly convert data types Pick up syntax quickly Visual Studio big help
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.