0% found this document useful (0 votes)
22 views13 pages

Chapter 1 - Introduction

C# is a multi-purpose programming language that is object-oriented and derived from C, designed for rapid application development with features like garbage collection and extensive class libraries. It supports various programming paradigms and is compatible with the .NET Framework, allowing integration with other .NET languages. The document includes detailed sections on language basics, advanced concepts, and the .NET framework, along with licensing information and contributor details.

Uploaded by

D3ath L3g3nd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views13 pages

Chapter 1 - Introduction

C# is a multi-purpose programming language that is object-oriented and derived from C, designed for rapid application development with features like garbage collection and extensive class libraries. It supports various programming paradigms and is compatible with the .NET Framework, allowing integration with other .NET languages. The document includes detailed sections on language basics, advanced concepts, and the .NET framework, along with licensing information and contributor details.

Uploaded by

D3ath L3g3nd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

C Sharp Programming

Wikibooks.org
March 18, 2013

On the 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia
projects were licensed under Creative Commons Attribution-ShareAlike 3.0 Unported license. An
URI to this license is given in the list of figures on page 165. If this document is a derived work
from the contents of one of these projects and the content was still licensed by the project under
this license at the time of derivation this document has to be licensed under the same, a similar or a
compatible license, as stated in section 4b of the license. The list of contributors is included in chapter
Contributors on page 159. The licenses GPL, LGPL and GFDL are included in chapter Licenses on
page 169, since this book and/or parts of it may or may not be licensed under one or more of these
licenses, and thus require inclusion of these licenses. The licenses of the figures are given in the list of
figures on page 165. This PDF was generated by the LATEX typesetting software. The LATEX source
code is included as an attachment (source.7z.txt) in this PDF file. To extract the source from the
PDF file, we recommend the use of http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
utility or clicking the paper clip attachment symbol on the lower left of your PDF Viewer, selecting
Save Attachment. After extracting it from the PDF file you have to rename it to source.7z. To
uncompress the resulting archive we recommend the use of http://www.7-zip.org/. The LATEX
source itself was generated by a program written by Dirk Hünniger, which is freely available under
an open source license from http://de.wikibooks.org/wiki/Benutzer:Dirk_Huenniger/wb2pdf.
This distribution also contains a configured version of the pdflatex compiler with all necessary
packages and fonts needed to compile the LATEX source included in this PDF file.
Contents

1 Introduction 3
1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 Microsoft .NET . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.6 Mono . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.7 Hello, World! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 Language Basics 9
2.1 Reasoning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2 Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.4 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.5 Statement blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.6 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.7 Case sensitivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.8 Fields, local variables, and parameters . . . . . . . . . . . . . . . . . . . . . . 16
2.9 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.10 Text & variable example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.11 Scope and extent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.12 Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.13 Logical . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.14 Bitwise shifting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.15 Relational . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.16 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.17 Short-hand Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.18 Type information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.19 Pointer manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.20 Overflow exception control . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.21 Others . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.22 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.23 Structs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.24 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.25 Conditional statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.26 Iteration statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.27 Jump statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
2.28 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.29 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
2.30 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

III
Contents

2.31 Re-throwing exceptions................................................................................................ 45

3 Classes 49
3.1 Nested namespaces ....................................................................................................... 50
3.2 Methods .......................................................................................................................... 52
3.3 Constructors of classes ................................................................................................. 52
3.4 Finalizers (Destructors) ................................................................................................ 53
3.5 Properties........................................................................................................................ 54
3.6 Indexers .......................................................................................................................... 55
3.7 Events .............................................................................................................................. 55
3.8 Operator overloading ................................................................................................... 58
3.9 Structures ........................................................................................................................ 59
3.10 Static classes ................................................................................................................... 61
3.11 References ....................................................................................................................... 61
3.12 Introduction ................................................................................................................... 61
3.13 Reference and Value Types ......................................................................................... 62
3.14 Object basics................................................................................................................... 63
3.15 Protection Levels ........................................................................................................... 68
3.16 References ....................................................................................................................... 71

4 Advanced Concepts 73
4.1 Inheritance ...................................................................................................................... 73
4.2 Subtyping Inheritance .................................................................................................. 74
4.3 Virtual Methods ............................................................................................................ 75
4.4 Constructors ................................................................................................................... 76
4.5 Inheritance keywords ................................................................................................... 77
4.6 References ....................................................................................................................... 78
4.7 Additional details.......................................................................................................... 79
4.8 Introduction ................................................................................................................... 80
4.9 Delegates......................................................................................................................... 80
4.10 Anonymous delegates .................................................................................................. 82
4.11 Events .............................................................................................................................. 83
4.12 Partial Classes ................................................................................................................ 84
4.13 Generic classes ............................................................................................................... 86
4.14 Generic interfaces .......................................................................................................... 87
4.15 Generic methods ........................................................................................................... 88
4.16 Type constraints ............................................................................................................ 89
4.17 Notes ............................................................................................................................... 90
4.18 Introduction ................................................................................................................... 91
4.19 Factory Pattern .............................................................................................................. 96
4.20 Singleton ......................................................................................................................... 98

5 The .NET Framework 99


5.1 Introduction ................................................................................................................... 99
5.2 Background .................................................................................................................... 99
5.3 Console Programming ............................................................................................... 100
5.4 System.Windows.Forms ............................................................................................. 116
5.5 Form class..................................................................................................................... 117

5.6 Events ............................................................................................................................ 117


5.7 Controls ......................................................................................................................... 118
1
Contents
5.8 Lists ................................................................................................................................ 119
5.9 LinkedLists ................................................................................................................... 120
5.10 Queues........................................................................................................................... 120
5.11 Stacks ............................................................................................................................. 120
5.12 Hashtables and dictionaries ...................................................................................... 121
5.13 The Thread class .......................................................................................................... 121
5.14 Sharing Data................................................................................................................. 123
5.15 Asynchronous Delegates ............................................................................................ 123
5.16 Synchronization ........................................................................................................... 124
5.17 GetSystemTimes .......................................................................................................... 126
5.18 GetProcessIoCounters ................................................................................................. 127

6 Keywords 129
6.1 References ..................................................................................................................... 133
6.2 The directive................................................................................................................. 154
6.3 The statement ............................................................................................................... 154
6.4 References ..................................................................................................................... 158

7 Contributors 159

List of Figures 165

8 Licenses 169
8.1 GNU GENERAL PUBLIC LICENSE . . . . . . . . . . . . . . . . . . . . . . 169
8.2 GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . . . 170
8.3 GNU Lesser General Public License . . . . . . . . . . . . . . . . . . . . . . . 171

1
Contents

1
1 Introduction

C#1 (pronounced "See Sharp") is a multi-purpose computer programming language 2 suitable


for all development needs.

1.1 Introduction

Although C# is derived from the C programming language 3, it has features such as garbage
collection4 that allow beginners to become proficient in C# more quickly than in C5 or
C++6. Similar to Java7, it is object-oriented8, comes with an extensive class library, and
supports exception handling, multiple types of polymorphism 9, and separation of interfaces
from implementations. Those features, combined with its powerful development tools,
multi-platform support, and generics, make C# a good choice for many types of software
development projects: rapid application development10 projects, projects implemented by
individuals or large or small teams, Internet applications, and projects with strict reliability
requirements. Testing frameworks such as NUnit11 make C# amenable to test-driven
development12 and thus a good language for use with Extreme Programming 13 (XP). Its
strong typing14 helps to prevent many programming errors that are common in weakly typed
languages. Because of this similarities to other languages, it is possible to introduce C#
as a language with features of C++ having the programming style of Java and the rapid
application model of BASIC.15
A large part of the power of C# (as with other .NET languages), comes with the common
.NET Framework API, which provides a large set of classes, including ones for encryption,
TCP/IP socket programming, and graphics. Developers can thus write part of an application
in C# and another part in another .NET language (e.g. VB.NET), keeping the tools, library,
and object-oriented development model while only having to learn the new language syntax.

1 http://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29
2 http://en.wikipedia.org/wiki/programming%20language
3 http://en.wikipedia.org/wiki/C%20programming%20language
4 http://en.wikipedia.org/wiki/Garbage%20collection%20%28computer%20science%29
5 http://en.wikibooks.org/wiki/Programming%3AC
6 http://en.wikibooks.org/wiki/Programming%3AC%20plus%20plus
7 http://en.wikipedia.org/wiki/Java%20programming%20language
8 http://en.wikipedia.org/wiki/object-oriented%20programming
9 http://en.wikipedia.org/wiki/polymorphism%20%28computer%20science%29
10 http://en.wikipedia.org/wiki/Rapid%20application%20development
11 http://en.wikipedia.org/wiki/NUnit
12 http://en.wikipedia.org/wiki/test-driven%20development
13 http://en.wikipedia.org/wiki/Extreme%20Programming
14 http://en.wikipedia.org/wiki/Strongly-typed%20programming%20language
15 Quick C# 16. The Code Project . Retrieved 2012-04-12 http://

3
Because of the similarities between C# and the C family of languages, as well as Java 17, a
developer with a background in object-oriented languages like C++ may find C# structure
and syntax intuitive.

1.2 Standard

w:C Sharp (programming language)18 Microsoft19, with Anders Hejlsberg20 as Chief Engineer,
created C# as part of their .NET21 initiative and subsequently opened its specification22
via the ECMA23. Thus, the language is open to implementation by other parties. Other
implementations include Mono24 and DotGNU25.
C# and other .NET languages rely on an implementation of the virtual machine26 specified
in the Common Language Infrastructure27, like Microsoft's Common Language Runtime28
(CLR). That virtual machine manages memory, handles object references, and performs
Just-In-Time (JIT) compiling of Common Intermediate Language29 code. The virtual
machine makes C# programs safer than those that must manage their own memory and is
one of the reasons .NET language code is referred to as managed code. More like Java than
C and C++, C# discourages explicit use of pointers, which could otherwise allow software
bugs to corrupt system memory and force the operating system to halt the program forcibly
with nondescript error messages.

1.3 History

Microsoft's original plan was to create a rival to Java, named J++, but this was abandoned
to create C#, codenamed "Cool".
Microsoft submitted C# to the ECMA standards group mid-2000.
C# 2.0 was released in late-2005 as part of Microsoft's development suite, Visual Studio
2005. The 2.0 version of C# includes such new features as generics, partial classes, and
iterators.30 32

17 http://en.wikipedia.org/wiki/Java%20programming%20language
18 http://en.wikipedia.org/wiki/C%20Sharp%20%28programming%20language%29
19 http://en.wikipedia.org/wiki/Microsoft
20 http://en.wikipedia.org/wiki/Anders%20Hejlsberg
21 http://en.wikipedia.org/wiki/Microsoft%20.Net
22 http://www.ecma-international.org/publications/standards/Ecma-334.htm
23 http://en.wikipedia.org/wiki/ECMA%20International
24 http://en.wikipedia.org/wiki/Mono%20development%20platform
25 http://en.wikipedia.org/wiki/DotGNU
26 http://en.wikipedia.org/wiki/virtual%20machine
27 http://en.wikipedia.org/wiki/Common%20Language%20Infrastructure
28 http://en.wikipedia.org/wiki/Common%20Language%20Runtime
29 http://en.wikipedia.org/wiki/Common%20Intermediate%20Language
30 The Father of C# on the Past, Present and Future of Programming 31. Microsoft Watch . Retrieved
2012-10-21 http://
32 C# Programming 33. Hitmill . Retrieved 2012-10-21 http://

4
References

1.4 References

Foreword34
To compile your first C# application, you will need a copy of a .NET Framework SDK
installed on your PC.
There are two .NET frameworks available: Microsoft's and Mono's.

1.5 Microsoft .NET

For Windows, the .NET Framework SDK can be downloaded from Microsoft's .NET
Framework Developer Center35. If the default Windows directory (the directory where
Windows or WinNT is installed) is C:\WINDOWS, the .Net Framework SDK installation places
the Visual C# .NET compiler (csc) in the
C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705 directory for version 1.0, the
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322 directory for version 1.1, or the
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 directory for version 2.0.

1.6 Mono

For Windows, Linux, or other Operating Systems, an installer can be downloaded from the
Mono website36. For Linux, a good compiler is cscc that can be downloaded for free from
the DotGNU Portable.Net project37 page. The compiled programs can then be run with
ilrun.

1.6.1 Linux

In Linux you can use the MonoDevelop IDE, and either download from their website at:
MonoDevelop Downloads38, or install via apt-get or your distro's installer.
• Debian-based distros:
sudo apt-get install monodevelop

• Arch Linux:
sudo pacman -S mono monodevelop

34 http://en.wikibooks.org/wiki/Category%3AC%20Sharp%20Programming
35 http://msdn.microsoft.com/netframework/
36 http://www.mono-project.com/Downloads
37 http://dotgnu.org/pnet.html
38 http://monodevelop.com/Download

5
1.6.2 Windows

You can download MonoDevelop from their website at: Mono website39. Click the Windows
icon, and follow the installation instructions.
If you are working on Windows it is a good idea to add the path to the folders that contain
cs.exe or mcs.exe to the Path environment variable so that you do not need to type the full
path each time you want to compile.
For writing C#.NET code, there are plenty of editors that are available. It's entirely possible
to write C#.NET programs with a simple text editor, but it should be noted that this
requires you to compile the code yourself. Microsoft offers a wide range of code editing
programs under the Visual Studio line that offer syntax highlighting as well as compiling
and debugging capabilities. Currently C#.NET can be compiled in Visual Studio 2002
and 2003 (only supports the .NET Framework version 1.0 and 1.1) and Visual Studio 2005
(supports the .NET Framework 2.0 and earlier versions with some tweaking). Microsoft
offers five Visual Studio editions40, four of which are sold commercially. The Visual Studio
C# Express Edition can be downloaded and used for free from Microsoft's website41.

1.7 Hello, World!

The code below will demonstrate a C# program written in a simple text editor. Start by
saving the following code to a text file called hello.cs:

using System;

namespace MyConsoleApplication
{
class MyFirstClass
{
static void Main(string[] args)
{
System.Console.WriteLine("Hello,");
Console.WriteLine("World!");

Console.ReadLine();
}
}
}

To compile hello.cs, run the following from the command line:


• For standard Microsoft installations of .NET 2.0, run
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe hello.cs
• For Mono run mcs hello.cs.
• For users of cscc, compile with cscc hello.cs -o hello.exe.
Doing so will produce hello.exe. The following command will run hello.exe:

39 http://www.mono-project.com/Downloads
40 http://msdn.microsoft.com/en-us/library/zcbsd3cz(VS.80).aspx
41 http://go.microsoft.com/?linkid=7653518

6
Hello, World!

• On Windows, use hello.exe.


• On Linux, use mono hello.exe or ilrun hello.exe.
Alternatively, in Visual C# express, you could just hit F5 or the green play button to run
the code. If you want to run without debugging, press CTRL-F5.
Running hello.exe will produce the following output:

Hello,
World!

The program will then wait for you to strike 'enter' before returning to the command prompt.
Note that the example above includes the System namespace via the using keyword. That
inclusion allows direct references to any member of the System namespace without specifying
its fully qualified name.
The first call to the WriteLine method of the Console class uses a fully qualified reference.

System.Console.WriteLine("Hello,");

The second call to that method shortens the reference to the Console class by taking
advantage of the fact that the System namespace is included (with using System).

Console.WriteLine("World!");

C# is a fully object-oriented language. The following sections explain the syntax of the C#
language as a beginner's course for programming in the language. Note that much of the
power of the language comes from the classes provided with the .NET framework, which are
not part of the C# language syntax per se.

7
8
9

You might also like