- Joined
- Apr 7, 2009
- Messages
- 647
- Reaction score
- 25
UPDATED!
--------------
Prerequisites:
A C# IDE (Visual Studio, SharpDevelop, etc)
Basic knowledge in computer programming
Lesson I: Understanding the Basics
Before you learn to code, you must understand why and how C# was created.
C# is a "son" of C++. C# was created to simplify C++, to compromise between power and easiness.
C
|
C++
/*****\
Java**C#
As you can see, Java is also a "son" of C++. However, Java cannot really be called as C#'s brother, but more like a cousin.
Where can C# be used?
It all depends on the framework you use.
The .NET framework, by Microsoft, is the most commonly used framework. the .NET framework operates ONLY on Windows operating systems.
Another common framework is the open-source Mono framework (
The Mono framework supports Linux, Mac OS X, and Windows.
Now, you might be asking, if Mono supports all those OSs, why even use the .NET framework?
The answer is simple.
Updates.
The Mono project will always be behind the .NET framework.
As of now, the Mono project is still behind by a bit.
But otherwise, if you're ok with that, then by all means, go get Mono.
Now, let's get started!
Lesson II: Learning C#'s In/Out System
Vocab to know:
Code block: A segment of code
namespace: a project name
class: a group of like functions and variables
library: a compiled file with functions
C# has a very easy to use I/O system.
To show you this, let's go ahead and make a program.
Create a new console project.
In VS, that would be File > New Project > C# > Console Application. (Other IDEs might have about the same stuff)
Open up the file with the Main() function.
If you don't have a file, or you just have an empty file, your IDE sucks cr...Just kidding.
Make a new file, by right-clicking on the project in the project explorer, and click 'new file'.
If asked what type, choose "Class"
If your file is empty, type this in.
The "using" block states which libraries to import. In this case, we're importing the System library.
namespace MyFirstCSharpApp
{
}
means that the code inside resides within the MyFirstCSharpApp, well, namespace.
Now, the
class Program
{
}
means that we're organizing a bunch of variables and functions into a category of "Program".
and finally,
public static void Main()
{
}
is a function. Main() is the first function called.
We'll talk a bit more about the public, static, and void keywords.
For now, let's just start writing our app.
Inside
public static void Main()
{
and
}
put
Console.WriteLine("My first ever application in C#!");
Now, debug.
Congratz!
You might notice that the console window immediately closes.
to fix that, add Console.ReadLine() under the WriteLine().
Now, let's take a look at the functions we added.
Let's look at the Console.WriteLine() function.
Console, is a class, just like the one you programmed in.
The "." operator opens up all the available functions and variables for use in the class. WriteLine() is a function in the Console. class.
The ("My first ever application in C#)! is what we call a parameter.
It's like a variable that we pass on to the function for use.
I'll write some more when i've got more time.
--------------
Prerequisites:
A C# IDE (Visual Studio, SharpDevelop, etc)
Basic knowledge in computer programming
Lesson I: Understanding the Basics
Before you learn to code, you must understand why and how C# was created.
C# is a "son" of C++. C# was created to simplify C++, to compromise between power and easiness.
C
|
C++
/*****\
Java**C#
As you can see, Java is also a "son" of C++. However, Java cannot really be called as C#'s brother, but more like a cousin.
Where can C# be used?
It all depends on the framework you use.
The .NET framework, by Microsoft, is the most commonly used framework. the .NET framework operates ONLY on Windows operating systems.
Another common framework is the open-source Mono framework (
You must be registered to see links
)The Mono framework supports Linux, Mac OS X, and Windows.
Now, you might be asking, if Mono supports all those OSs, why even use the .NET framework?
The answer is simple.
Updates.
The Mono project will always be behind the .NET framework.
As of now, the Mono project is still behind by a bit.
But otherwise, if you're ok with that, then by all means, go get Mono.
Now, let's get started!
Lesson II: Learning C#'s In/Out System
Vocab to know:
Code block: A segment of code
namespace: a project name
class: a group of like functions and variables
library: a compiled file with functions
C# has a very easy to use I/O system.
To show you this, let's go ahead and make a program.
Create a new console project.
In VS, that would be File > New Project > C# > Console Application. (Other IDEs might have about the same stuff)
Open up the file with the Main() function.
If you don't have a file, or you just have an empty file, your IDE sucks cr...Just kidding.
Make a new file, by right-clicking on the project in the project explorer, and click 'new file'.
If asked what type, choose "Class"
If your file is empty, type this in.
Code:
using System;
namespace MyFirstCSharpApp
{
class Program
{
public static void Main()
{
}
}
}
The "using" block states which libraries to import. In this case, we're importing the System library.
namespace MyFirstCSharpApp
{
}
means that the code inside resides within the MyFirstCSharpApp, well, namespace.
Now, the
class Program
{
}
means that we're organizing a bunch of variables and functions into a category of "Program".
and finally,
public static void Main()
{
}
is a function. Main() is the first function called.
We'll talk a bit more about the public, static, and void keywords.
For now, let's just start writing our app.
Inside
public static void Main()
{
and
}
put
Console.WriteLine("My first ever application in C#!");
Now, debug.
Congratz!
You might notice that the console window immediately closes.
to fix that, add Console.ReadLine() under the WriteLine().
Now, let's take a look at the functions we added.
Let's look at the Console.WriteLine() function.
Console, is a class, just like the one you programmed in.
The "." operator opens up all the available functions and variables for use in the class. WriteLine() is a function in the Console. class.
The ("My first ever application in C#)! is what we call a parameter.
It's like a variable that we pass on to the function for use.
I'll write some more when i've got more time.
Last edited by a moderator: