2

C# Fundamentals

2.1 INTRODUCTION AND OBJECTIVES

The goal of this chapter is to introduce the C# language. We concentrate on fundamental issues such as built-in data types, memory management and basic console input and output. Of particular importance is the distinction between value types and reference types, how they are created, compared and finally removed from memory.

Without further ado, we deliver the extremely popular “Hello World” program:

using System;	 // Use the System namespace (Console etc.)
// HelloWorld class. Every C# program has at least one class
public class HelloWorld
{ // Each Main method must be enclosed in a class
   // C# programs start in this Main() method
   public static void Main()
   {
	 // Write string to console
	 Console.WriteLine("Hello world!");
   }
}

In this case we have created a class called HelloWorld containing a method called Main() which is the entry point to the program. We explain this (and more extended) syntax in the rest of this chapter.

We are assuming that the reader has knowledge of programming in some object-oriented language, in particular what classes and objects are, some knowledge of data types and basic exception handling. For those readers with minimal programming experience and who need to learn fundamental C# syntax, please consult a book on C#, for example Albahari 2010. In this chapter we deliver a simple C# class that implements the Black Scholes equation. For an introduction to object-oriented programming, see Appendix ...

Get C# for Financial Markets now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.