Table of Contents Preface Bare Necessities... 17

Similar documents
Language Specification

C # Language Specification

Introduce C# as Object Oriented programming language. Explain, tokens,

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

.Net Technologies. Components of.net Framework

C#: framework overview and in-the-small features

Welcome to Teach Yourself Acknowledgments Fundamental C++ Programming p. 2 An Introduction to C++ p. 4 A Brief History of C++ p.

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Introduction to C# Applications

ISO/IEC INTERNATIONAL STANDARD. Information technology Programming languages C# Technologies de l'information Langages de programmation C#


Object-Oriented Programming in C# (VS 2015)

Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.

Object-Oriented Programming in C# (VS 2012)

Absolute C++ Walter Savitch

Microsoft. Microsoft Visual C# Step by Step. John Sharp

Operators and Expressions

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

Axivion Bauhaus Suite Technical Factsheet MISRA

Review of the C Programming Language for Principles of Operating Systems

C# Language Reference

Language Reference Manual simplicity

Microsoft Visual C# Step by Step. John Sharp

Introduction to Programming Using Java (98-388)

1 Lexical Considerations

6.096 Introduction to C++ January (IAP) 2009

This tutorial has been prepared for the beginners to help them understand basics of c# Programming.

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

C# Language Specification

C-LANGUAGE CURRICULAM

Introduction to C++/CLI 3. What C++/CLI can do for you 6 The rationale behind the new syntax Hello World in C++/CLI 13

DigiPen Institute of Technology

Interview Questions of C++

OVERVIEW ENVIRONMENT PROGRAM STRUCTURE BASIC SYNTAX DATA TYPES TYPE CONVERSION

C# Programming in the.net Framework

COPYRIGHTED MATERIAL. Contents. Part I: C# Fundamentals 1. Chapter 1: The.NET Framework 3. Chapter 2: Getting Started with Visual Studio

C++ (Non for C Programmer) (BT307) 40 Hours

Review of the C Programming Language

Learning C# 3.0. Jesse Liberty and Brian MacDonald O'REILLY. Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo

Lexical Considerations

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

1 Shyam sir JAVA Notes

Lexical Considerations

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

UNIT- 3 Introduction to C++

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

3. Java - Language Constructs I

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Practical C++ Programming

Chapter 6. Simple C# Programs

Visual C# Instructor s Manual Table of Contents

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

CSCI 171 Chapter Outlines

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Index COPYRIGHTED MATERIAL

Program Fundamentals

A flow chart is a graphical or symbolic representation of a process.

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value


Short Notes of CS201

Axivion Bauhaus Suite Technical Factsheet AUTOSAR

CERTIFICATE IN WEB PROGRAMMING

A Short Summary of Javali

CS201 - Introduction to Programming Glossary By

Tokens, Expressions and Control Structures

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

Object-Oriented Programming

CODE TIME TECHNOLOGIES. Abassi RTOS MISRA-C:2004. Compliance Report

Chapter 3 Structure of a C Program

C++/CLI in Action NISHANT SIVAKUMAR MANNING. Greenwich (74 w. long.)

Course Hours

QUIZ. Write the following for the class Bar: Default constructor Constructor Copy-constructor Overloaded assignment oper. Is a destructor needed?

Introduction to C++ Introduction. Structure of a C++ Program. Structure of a C++ Program. C++ widely-used general-purpose programming language

Object Oriented Programming

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Lesson Plan. Subject: OBJECT ORIENTED PROGRAMMING USING C++ :15 weeks (From January, 2018 to April,2018)

Client-Side Web Technologies. JavaScript Part I

Java Primer 1: Types, Classes and Operators

Introduction to C++ with content from

Information technology C# Language Specification


C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

Computer Science 306 Study Guide

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Objective of the Course: (Why the course?) Brief Course outline: (Main headings only) C# Question Bank Chapter1: Philosophy of.net

Introduction to C++ Systems Programming

KLiC C++ Programming. (KLiC Certificate in C++ Programming)

C++ Important Questions with Answers

CS201 Some Important Definitions

>B<82. 2Soft ware. C Language manual. Copyright COSMIC Software 1999, 2001 All rights reserved.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

Prerequisites: The student should have programming experience in a high-level language. ITCourseware, LLC Page 1. Object-Oriented Programming in C#

Programming Languages Third Edition. Chapter 7 Basic Semantics

IBM i Version 7.2. Programming IBM Rational Development Studio for i ILE C/C++ Language Reference IBM SC

Chapter 02 Building Multitier Programs with Classes

Transcription:

Table of Contents Preface... 13 What this book is about?... 13 Who is this book for?... 14 What to read next?... 14 Personages... 14 Style conventions... 15 More information... 15 Bare Necessities... 17 C# C-Sharp... 17 CLI Common Language Infrastructure a.k.a. CLR Common Language Runtime... 17 Your first C# program Hello-o-o, world!... 18 Program entry point... 19 Good news:.net Framework SDK... 19 Compiling the first program... 19 Automatic memory management... 21 System.Console object... 21 Basics... 22 Identifiers... 22 Keywords... 23 Data types... 24 Unified type system... 24 Predefined simple types... 25 Value types... 26 Real numbers... 26 Enumeration (enum) types... 26 Structure (struct) types... 27 Reference types... 28 Predefined reference types... 28 Class types... 28 Interface types... 29 Delegate types... 30 Array types... 30 Boxing and Unboxing... 30 Unsafe code and Pointers... 31 Literals... 31 Boolean literals... 31 Integer literals... 32 Real literals... 32 Character literals... 33 String literals... 34 Assemblies... 35 Namespaces a.k.a. libraries, Members and Access... 35

8 Members... 37 Accessibility declaration and access modifiers... 38 Accessibility domains... 39 Scope... 40 Expressions... 43 Operator precedence... 43 Operators... 44 Overloadable operators... 46 Parenthesized expression (x)... 46 Member access x.y... 46 Invocation a.k.a. member (function) call f(x)... 46 Argument lists... 47 The ref and out parameters... 47 Variable number of parameters... 49 Element access a[x]... 49 Postfix increment x++ and decrement x--... 50 this and base access... 50 Create a new instance: new()... 51 Creating an object... 51 Creating an array... 52 Creating a delegate... 52 typeof... 53 checked and unchecked... 54 Unary + and -... 54 Unary! and ~... 55 Prefix increment ++x and decrement --x... 55 Typecast (T)x... 55 Implicit conversions... 56 Explicit conversions... 56 Multiplicative: Multiplication *, Division /, and Remainder %... 57 Additive: Addition + and Subtraction -... 58 Shift left << and shift right >>... 58 Relational: < > <= >=... 59 Equality: == and!=... 59 Relational: is... 60 No-exceptions typecast: as... 61 Logical and : &, exclusive or : ^, and or :... 61 Conditional and : &&, and or :... 62 Conditional?:... 62 Assignment = *= /= %= += -= <<= >>= &= ^= =... 62 Statements and flow control... 63 End points and reachability... 63

Statement lists and blocks... 63 Empty statement... 63 Local declarations... 64 Expression... 65 Labels and goto statement... 65 break and continue statements... 66 if statement... 66 switch statement... 67 while statement... 69 do statement... 69 for statement... 69 foreach statement... 70 return statement... 71 throw statement... 71 try statement... 72 checked and unchecked statements... 73 lock statement... 74 Preprocessor... 75 #define and #undef... 75 #if, #elif, #else and #endif... 76 Preprocessor expressions... 76 #error and #warning... 77 #region and #endregion... 77 #line... 78 Unsafe code... 79 Compare value, reference and pointer types... 79 Marking code as unsafe... 80 Unsafe code and Pointers... 80 sizeof()... 81 stackalloc()... 81 Fixed and movable variables... 82 fixed statement... 82 Classes and Objects... 85 Object-Oriented Language(s)... 85 Objects and Messages... 85 Abstract Classes, Properties, and Messages... 86 Classes and Objects, Instances... 86 Inheritance... 87 Interfaces... 87 Polymorphism... 88 Classes in C#... 88 Simple class... 88 Class declarations... 89 Static members... 90 Inheritance related modifiers... 92 abstract modifier... 92 9

10 virtual modifier... 92 override modifier... 92 new modifier... 92 sealed modifier... 92 extern modifier... 93 Fields... 93 Methods... 95 The ref and out parameters... 96 Operators... 96 Properties... 100 Indexers... 103 Events... 104 Instance constructors... 106 Static constructors... 109 Destructors... 111 Structures... 113 Treating this in structure methods... 115 Including itself... 116 Namespaces... 116 Namespace declarations... 116 Using namespaces using... 117 Enumerations... 118 Enumeration (enum) declarations... 118 Inheritance... 119 Inheritance... 119 Signatures, overloading methods... 120 Polymorphism, downcasting, upcasting... 122 Virtual methods, overriding and hiding methods... 123 Abstract classes and methods... 125 Sealed classes and methods... 126 Interfaces... 127 Interface declarations... 127 Using interfaces... 128 Explicit interface member implementations... 131 Ambiguity with interface member implementations... 132 Abstract class vs. interface... 133 Delegates... 133 Parameters and return value... 135 Nature of delegates... 135 Delegate declaration... 135 Delegate instantiation... 136 Delegate invocation... 136 Attributes... 136 AttributeUsage attribute... 137

Conditional attribute... 138 Obsolete attribute... 139 Interoperability with native code... 141 Attributes... 141 ComAliasName attribute... 141 ComImport attribute... 142 ComRegisterFunction attribute... 142 ComSourceInterfaces attribute... 143 ComUnregisterFunction attribute... 143 ComVisible attribute... 143 DispId attribute... 143 DllImport attribute... 143 FieldOffset attribute... 144 Guid attribute... 144 HasDefaultInterface attribute... 144 ImportedFromTypeLib attribute... 144 In and Out attributes... 144 IndexerName attribute... 145 InterfaceType attribute... 145 MarshalAs attribute... 145 NoIDispatch attribute... 145 PreserveSig attribute... 145 StructLayout attribute... 145 TypeLibFunc attribute... 145 TypeLibType attribute... 146 TypeLibVar attribute... 146 Calling COM and ActiveX Objects from C# - practical approach... 146 Creating interop assembly... 146 Using interop assembly... 147 Primary interop assembly (PIA)... 147 Dangers of alternative interop assembly... 148 Base Class Library.Net Framework SDK... 148 Appendix A. Keywords... 149 Appendix B. Formal Grammar... 157 Lexical grammar... 157 Line terminators... 158 White space... 158 Comments... 158 Tokens... 159 Unicode character escape sequences... 159 Identifiers... 159 Keywords... 160 Literals... 160 11

12 Operators and punctuators... 162 Pre-processing directives... 162 Syntactic grammar... 164 Basic concepts... 164 Types... 165 Variables... 166 Expressions... 166 Statements... 169 Namespaces... 172 Classes... 173 Structs... 179 Arrays... 179 Interfaces... 180 Enums... 181 Delegates... 181 Attributes... 182 Grammar extensions for unsafe code... 183 Unsafe contexts... 183 Pointer types... 184 Pointers in expressions... 184 Pointer indirection... 184 Pointer member access... 184 The address-of operator... 185 The sizeof operator... 185 The fixed statement... 185 Stack allocation... 185 Appendix C. C# Compiler Command-Line Options... 187 Index... 189