Jump to content

C Sharp syntax

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Sundström (talk | contribs) at 14:40, 9 October 2007 (Created page with '{{pound|C# Syntax}} : ''Main article: C#'' The syntax of the C# is a set of rules which defines how to write and interprete code. == Basics == === Ide...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

#

Main article: C#

The syntax of the C# is a set of rules which defines how to write and interprete code.

Basics

Identifier

An identifier is the name of an elemet in the code. There are certain naming conventions that you should follow when you are naming elements yourself.

((Conventions))

Keywords

Keywords are reserved words that you cannot use when you are naming your own variables.

((Table of keywords))

Variables

Variables are places for storing values. They are declared by writing the name of the type and the name you will assign to the variable.

Declare

   int MyInt;         //Declaring an variable.

Initiate

   int MyInt = 35;    //Declaring and initiating.

   MyInt = 106;       //Initiating and already declared variable.


Data types

Primitive types

User-defined types

Classes

A class is a reference type...

struct Hour
{
   public Hour
}
Inheritance

A class can inherit another and get they same fields and methods as the base class.



Structures

Commonly just known as Structs. The syntax of a struct is similar to a class's. But a struct is a value types and does therfore not refer to and object on the heap.

struct Hour
{
   private int hours;      //Field
   private int minutes;    //Field
   private int seconds;    //Field

   public Hour(int hours, int minutes, int seconds)    //Constructor
   {
      this.hours = hours;
      this.minutes = minutes;
      this.seconds = seconds;
   }
}

Primitive types like int and double are structures. But strings and and arrays are classes.

Enumerations

Enumerations, or simply Enums, are user-defined types which...

enum Seasons
{
   Spring, Summer, Autumn, Fall = 2, Winter
}

Delegates

More

Classes and Structs

Constructor

Desctructor

Method

Field

A field is a variable declared and shared within a class or struct.

Properties

Indexers

Inheritance

Classes can inherit another. In fact all types inherit the class Object.