1 / 21

C# Language

C# Language. MIS 324 Professor Sandvig. Overview. Why learn C#? C# Basics Variables Data types Operators Control Structures. Why Learn C#?. Modern language Microsoft introduced in 2000 More user-friendly than older languages Managed code Memory allocation Garbage collection

gilliamj
Download Presentation

C# Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C# Language MIS 324 Professor Sandvig

  2. Overview • Why learn C#? • C# Basics • Variables • Data types • Operators • Control Structures

  3. Why Learn C#? • Modern language • Microsoft introduced in 2000 • More user-friendly than older languages • Managed code • Memory allocation • Garbage collection • 100% object oriented • Widely used

  4. 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. 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. Variables • Commonly Used C# Data Types

  8. Datatype Conversion • Implicit Conversion • Done when no data lost

  9. Datatype Conversion • Web Forms • 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 • Control structures • Classes • Good:

  13. Common C# Operators Control Structures examples

  14. Control Structures • Syntax similar to C, JavaScript, PHP, Java, … • Curley brackets for statement blocks if (condition) { //Statement block } else { //statement block }

  15. Control Structures • May omit brackets for single statements: if (condition) statement 1; else statement 2;

  16. Control Structures • Similar in all languages • Syntax may be different • if • for • foreach • while

  17. Control Structures • 1. if else: if (condition) { //do something } else if (condition) { //do something } else { //do something else }

  18. 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. 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. Control Structures • 4. while loop int i = 0; while (i < 5) { i += 1; }

  21. Summary • C# modern object oriented programing language • Relatively easy to use • Managed code • C-like syntax (similar toPHP, JavaScript, C, C++) • Strongly typed • Explicitly convert data types • Pick up syntax quickly • Visual Studio big help

More Related