Learn C Sharp Lesson 1
Learn C Sharp Lesson 1
First tutorial
You should first open a DOS command shell.
(If you don't know what it is, clic on the
Start menu then run (at the bottom) and
type, in the text field: "cmd".
exercise: there is an easiest way to do that,
try to find it.)
You should begin to work in an empty
directory for this. let call it "C:\learncs".
Type in the shell:
> md C:\learncs
> cd C:\learncs
> C:
Second tutorial
Congratulation you've done the most
difficult, let increase the difficulty. and
create an object instance. in the DOS shell
create a new directory:
> md ..\learncs2
> cd ..\learncs2
> notepad hello.cs
Third tutorial
Now you become to be pretty confident, I
guess, so we could start using multiple file,
and even a dll ? go into an other directory (or
stay in this one, I won't mind) and create 2
file:
hello.cs
using System;
echo.cs
using System;
namespace HelloUtil
{
public class Echo
{
string myString;
Fourth tutorial
Congratulation you would soon be able to
hack CsGL but there is one last step you
should understand : interop (with C code).
You will need a C compiler, I advise gcc for
windows called MinGW, it's free, it's good,
it's GCC!
We will create 3 file:
echo.c
#include <stdio.h>
#define DLLOBJECT
__declspec(dllexport)
echo.cs
using System;
using System.Runtime.InteropServices;
namespace HelloUtil
{
public class Echo
{
[DllImport("echo.native.dll",
CallingConvention=CallingConvention.Cdecl)]
static extern void writeln(string s);
string myString;
hello.cs
using System;
using HelloUtil;
And now..
Well, first forget about notepad. It's good to
learn, but so painfull to use regularly.., try to
find real developer friendly small text editor
(like JFE) or a complete IDE like
SharpDevelop.