Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
It is object oriented.
It is component oriented.
It is easy to learn.
It is a structured language.
Windows applications
Web applications
Web services
Namespace declaration
A class
Class methods
Class attributes
A Main method
Comments
using System;
namespace HelloWorldApplication
{
class HelloWorld
{
static void Main(string[] args)
{
/* my first program in C# */
Console.WriteLine("Hello World");
Console.ReadKey();
}
}
}
If you are using Visual Studio.Net for compiling and executing C# programs,
take the following steps:
Click the Run button or press F5 key to execute the project. A Command
Prompt window appears that contains the line Hello World.
Defining a Namespace
A namespace definition begins with the keyword namespace followed by the namespace
name as follows
namespace namespace_name
{
// code declarations
}
To call the namespace-enabled version of either function or variable, prepend the namespace
name as follows:
namespace_name.item_name;
using System;
namespace first_space
{
class namespace_cl
{
public void func()
{
Console.WriteLine("Inside first_space");
}
}
}
namespace second_space
{
class namespace_cl
{
public void func()
{
Console.WriteLine("Inside second_space");
}
}
}
class TestClass
{
static void Main(string[] args)
{
first_space.namespace_cl fc = new first_space.namespace_cl();
second_space.namespace_cl sc = new second_space.namespace_cl();
fc.func();
sc.func();
Console.ReadKey();
}
}
using System;
using first_space;
using second_space;
namespace first_space
{
class abc
{
public void func()
{
Console.WriteLine("Inside first_space");
}
}
}
namespace second_space
{
class efg
{
public void func()
{
Console.WriteLine("Inside second_space");
}
}
}
class TestClass
{
static void Main(string[] args)
{
abc fc = new abc();
efg sc = new efg();
fc.func();
sc.func();
Console.ReadKey();
}
}
Nested Namespaces
You can define one namespace inside another namespace as follows:
namespace namespace_name1
{
// code declarations
namespace namespace_name2
{
// code declarations
}
}
using System;
namespace csharpclass
// nested namespace
namespace sclass
class myExample1
Console.ReadLine();
}
}
class NamespaceCalling
sclass.myExample1.myPrint1();
sclass.myExample2.myPrint2();
namespace csharpclass.sclass
class myExample2
Console.ReadLine();
C# supports two forms of string literals: regular string literals and verbatim string literals.
Escape Sequence
An escape sequence is a series of special characters which are interpreted by the compiler
as a command. In other words, they suspend the normal processing to perform some special
function.
using System;
verbatim string
A verbatim string literal consists of an @ character followed by a double-quote character,
zero or more characters, and a closing double-quote character. A simple example is @"hello".
In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the
only exception being a quote-escape-sequence.
The @ symbol tells the string constructor to ignore escape characters and line breaks.
Using System;
Class Program
Console.WriteLine(Name);
}
using System;
class Verbatim {
Console.WriteLine(@"This is a verbatim
Console.ReadLine();
using System;
class Program
Another line";
{
//
//
//
//
Console.WriteLine(
"{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n{7}\n{8}\n{9}",