
<p><strong>Course 419 </strong></p><p><strong>C# Programming </strong></p><p>G419/CN/E.1/609/D.1 </p><p>© LEARNING TREE INTERNATIONAL, INC. <br>All rights reserved. </p><p>All trademarked product and company names are the property of their respective trademark holders. </p><p>No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, or translated into any language, without the prior written permission of the publisher. </p><p>Copying software used in this course is prohibited without the express permission of Learning Tree International, Inc. Making unauthorized copies of such software violates federal copyright law, which includes both civil and criminal penalties. </p><p><strong>Introduction and Overview </strong></p><p><strong>Course Objectives </strong></p><p> <strong>In this course, we will discuss the syntax and semantics of C# as </strong></p><p>• An <em>object-oriented </em>language <br>◦ Using <em>encapsulation</em>, <em>inheritance</em>, <em>interfaces</em>, <em>realization</em>, <em>polymorphism</em>, <em>associations</em>, and <em>aggregates </em><br>• A <em>component-oriented </em>language focusing on reuse via the .NET <em>Framework </em><br><em>Library</em>, including </p><p>◦ Desktop graphical and web-based user interfaces ◦ Enabling cross-language operation ◦ Performing I/O using serial streams and serialization ◦ Interfacing to legacy COM components </p><p>• A <em>data-oriented </em>language <br>◦ Using <em>LINQ </em>and the <em>Entity Framework </em></p><p>COM = component object model I/O = input/output LINQ = Language Integrated Query </p><p><strong>Intro-2 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>Course Contents </strong></p><p><strong>Introduction and Overview </strong><br><strong>Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9 Chapter 10 </strong><br><strong>Overview and Development Environment From Your Language to C# User Interface Development Defining User-Written Data Types The .NET Framework Interfaces and Polymorphism Writing .NET Components Accessing Databases Other C# Features Course Summary Next Steps </strong></p><p><strong>Intro-3 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>Course Contents </strong></p><p><strong>Appendix A Appendix B Appendix C </strong><br><strong>Performance Tips Unsafe Features Other C# Features </strong></p><p><strong>Intro-4 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>Prerequisites </strong></p><p> <strong>Although this course is an introduction to C#, it is intended for </strong></p><p><strong>experienced programmers </strong></p><p>• A background in a modern <em>procedural </em>language is needed <br>◦ For example: C/C++, Java, VB, VB.NET, Pascal <br>• You will need to be comfortably familiar with concepts such as </p><p>◦ Data types, variables, declarations, conditionals, loops, expressions, functions, parameter passing, and procedural language flow </p><p> <strong>Course 502, Programming With .NET Introduction, is recommended if you have only </strong></p><p>• HTML or SQL experience • Experience in languages like COBOL, RPG, PL/SQL, T-SQL </p><p> <strong>Some modest exposure to object-oriented concepts is also assumed </strong></p><p><strong>Please notify your instructor if you do not meet the prerequisites </strong></p><p>COBOL = common business-oriented language HTML = hypertext markup language PL/SQL = procedural language/structured query language <br>SQL = structured query language T-SQL = Transact-SQL VB = Visual Basic </p><p><strong>Intro-5 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>Course Fonts and Icons </strong></p><p> <strong>These fonts and symbols have special meaning in the Course Notes: </strong></p><p>• Text in <em>Century Schoolbook italic </em>introduces a new concept or term • Text in <strong>Courier bold </strong>is C# code keywords or command text • Text in plain Courieris program output or C# code • Text in <em>Courier italic </em>is nonliteral code or command text </p><p><strong>Slippery When Wet </strong><br><strong>Question </strong></p><p>Potentially confusing or variance from common use in other languages <br>Question for the attendee </p><p><strong>Surfer </strong><br><strong>Warning </strong></p><p>Additional information can be found at this web reference <br>Feature that if used incorrectly can lead to problems </p><p><strong>Version n </strong><br><strong>Crystal Ball </strong></p><p>This feature is available only in C# version n or later. For example, the note below would indicate that the capability discussed requires at least C# V6 <br>Reference to material that will be discussed later </p><p><strong>Good Idea </strong></p><p>Feature to make programs easier to write or maintain </p><p><strong>Intro-6 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>Chapter 1 </strong></p><p><strong>Overview and Development </strong><br><strong>Environment </strong></p><p><strong>Chapter Objectives </strong></p><p><strong>In this chapter, we will examine </strong> <strong>A brief history of C# </strong> <strong>Some elementary features of the language </strong> <strong>How to use our development tools </strong></p><p><strong>1-2 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>Chapter Contents </strong></p><p> <strong>Evolution From C to C# </strong></p><p>• <strong>Development Environment </strong>• <strong>Hands-On Exercise 1.1 </strong>• <strong>Review Questions </strong></p><p><strong>1-3 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>Differences and Similarities </strong></p><p> <strong>C# has borrowed many concepts and constructs from other languages </strong></p><p>• In particular, C++, Java, VB, and SQL </p><p> <strong>Depending on your background, some aspects of C# might seem the same as a language you have previously used, but … </strong></p><p><strong>Don’t be fooled! </strong></p><p>• In the midst of the familiar, there will often be some unexpected differences </p><p> <strong>The course is written with these differences and similarities in mind </strong></p><p><strong>1-4 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>C-Style Syntax </strong></p><p> <strong>It all started with C </strong></p><p>• Dennis Ritchie at Bell Labs in 1971 • <em>The </em>language of choice on UNIX and PCs in the 1970s and 1980s <br>◦ Still widely used </p><p> <strong>C introduced what is now called C-style syntax </strong></p><p>• Each statement ends in a semicolon (;) • Code blocks (<em>body</em>) are enclosed between {and } • Uppercase and lowercase are distinct • Function-oriented; e.g., mainand printf </p><p>#<strong>include </strong><stdio.h> <strong>int </strong>main(<strong>void</strong>) </p><p>{printf("Hello world!\n"); </p><p><strong>return </strong>0; </p><p>}</p><p><strong>1-5 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>C-Style Syntax </strong></p><p> <strong>C-style syntax is free-format </strong></p><p>• Input is broken into <em>tokens </em>by the compiler • The order of the tokens is important, but not their column positions </p><p> <strong>For example, these programs are semantically identical: </strong></p><p><strong>int </strong></p><p>main( </p><p><strong>int </strong>main(<strong>void</strong>) </p><p>{</p><p><strong>void </strong></p><p>) { printf ("Hello World\n") </p><p>; <strong>return </strong></p><p>0; } printf("Hello World\n"); </p><p><strong>return </strong>0; </p><p>}</p><p><strong>int </strong>main(<strong>void</strong>) {printf("Hello World\n"); <strong>return </strong>0;} </p><p><strong>Good engineering practice suggests adopting a clear, properly indented, consistent coding style </strong></p><p>• This course demonstrates the generally accepted Microsoft coding style </p><p><strong>1-6 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>Evolution From C </strong></p><p> <strong>The C language eventually evolved into other languages with similar syntax, such as C++ </strong></p><p>• Which added object orientation </p><p><strong>… and then Java </strong></p><p>• Which was more portable and easier to program than C++ <br>◦ But with reduced performance </p><p><strong>… and then JavaScript (JScript) </strong></p><p>• For scripting and web niches </p><p><strong>… and then … </strong></p><p><strong>1-7 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>C# History </strong></p><p> <strong>C# appeared in 2001 as the “first 21st-century language” </strong></p><p>• Developed by Microsoft for its .NET initiative • Follows the C/C++/Java trend <br>◦ But also borrows from Visual Basic, Smalltalk, Lisp, and others </p><p> <strong>Designed to be </strong></p><p>• Easier to write and much less error-prone than C++ • More efficient with better performance than Java • Multimission—to be used for virtually any kind of application • Multilayer—to be the language of choice in any application layer </p><p> <strong>C# is </strong></p><p>• <em>Object-Oriented </em>(OO), supporting all modern OO concepts • <em>Component-Oriented </em>(CO), with CO features built into the language • <em>Data-oriented</em>, with SQL-like data-manipulation built into the language </p><p>◦ Called <em>Language INtegrated Query </em>(LINQ) </p><p><strong>1-8 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>C# Versions and Standards </strong></p><p> <strong>C# is not Microsoft’s language per se </strong></p><p>• Standardized through ECMA and ISO/IEC </p><p> <strong>Microsoft version is called Visual C# .NET</strong><sup style="top: -0.4em;"><strong>® </strong></sup></p><p>• February 2002: V1—pre-standard version had most language features <br>• November 2005: V2—fully compliant with 23270 1st edition • December 2007: V3—fully compliant with ECMA-344 4th edition • April 2010: V4—fully compliant, adds extended features • August 2012: V5—fully compliant, adds extended features • July 2015: V6—fully compliant, adds numerous small, very useful features </p><p>ECMA = European Computer Manufacturers Association IEC = International Electrotechnical Commission <br>ISO = International Organization for Standardization </p><p><strong>1-9 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>Hello World in C# </strong></p><p> <strong>Here is the “Hello World” program in C#: </strong></p><p><strong>using </strong>System; <strong>public class </strong>HelloWorld </p><p>{</p><p><strong>public static int </strong>Main() </p><p>{<br>Console.Write("Hello world!\n"); </p><p><strong>return </strong>0; </p><p>}<br>}</p><p> <strong>Syntax is similar and output is identical to previous C program </strong></p><p>• Main<em>method </em>(function) is in a <em>class </em></p><p>• Uses Console.Writemethod from the .NET framework library • Otherwise, it has mostly the same tokens and keywords </p><p>C:\Course\419\Samples\HelloWorldExample </p><p><strong>1-10 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p><p><strong>Comments </strong></p><p> <strong>In a C# program, only comments are not tokenized </strong></p><p>• Considered <em>whitespace </em>by the compiler </p><p> <strong>There are three different styles </strong></p><p>• <em>Multiline </em>starts with /*and ends with */ • <em>Single-line </em>starts with //and finishes at the end of the line </p><p>• <em>XML-based </em>documentation uses /// </p><p>///<summary> /// This will be included in the documentation and IntelliSense ///</summary> </p><p><strong>public static int </strong>Main() </p><p>{/* This style of comment can go over over multiple lines. */ </p><p><strong>int </strong>i = 100; // This style goes to the end of the line. <br>}</p><p>XML = extensible markup language </p><p><strong>1-11 </strong></p><p><strong>© Learning Tree International, Inc. All rights reserved. Not to be reproduced without prior written consent. </strong></p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages422 Page
-
File Size-