Feedback results
A little bit about C # and * nix
Many people are interested in how you can write on C # in * nix systems. I will try to help our friends. There is a Mono project and this is what Wikipedia tells us:
Mono - a project to create a full-fledged implementation of the .NET system based on free software.
Mono includes a C # - mcs compiler, .NET runtime - mono (with JIT support) and mint (without JIT support), a debugger, and a number of libraries, including the implementation of ADO.NET and ASP.NET. The project also develops bindings for the GTK + graphics system to the .NET platform.
The mono runtime can execute modules written in C #, Visual Basic .NET, Java, Boo, Nemerle, Python, JavaScript, PHP, and Object Pascal (if you have a .Net / Mono compiler). C, Ada 2005 and Eiffel languages ​​are also expected.
Mono implementations exist for the following operating systems: GNU / Linux, Solaris, Mac OS X, Microsoft Windows and Unix.
And this tells us that we can safely program in almost any C # OS. The latest release of the Mono Project is 2.2.
Mono Project - here you can download the latest version, as well as view the documentation.
There is also another good news. The Mono development team has a subsidiary project -
MonoDevelop . This is a free IDE for C # and ASP.NET. It supports all the necessary features for successful and rapid development in * nix systems.
My neighbor - my friend
Since an article about programming languages ​​such as Ruby and Python is being written next door, you should be very close to your neighbors.
IronRubyIronRuby is an implementation of the Ruby programming language on the Microsoft .NET platform. The interpreter is implemented on the basis of Dynamic Language Runtime, a library running on CLR 2.0, which provides, among other things, dynamic typing and dynamic method definition.
IronpythonIronPython — one of the main implementations of the Python language, intended for the Microsoft .NET or Mono platform. Fully written in C #, and is a compiler type translator.
You can use .NET types in IronPython. You can also use IronPython code from .NET code, either by hosting an IronPython system or by pre-assembling IronPython code.
Ironpython')
And read?
From books for me,
C # was for professionals . Authors: Simon Robinson, Oldie Cornes, Jay Glyn, Barton Harvey, etc. I started right from her, but as I had programming experience and if you don’t have one, I recommend reading
C # Author: Carly Watson.
C # Author: Carly Watson.C # for professionals. Authors: Simon Robinson et al.Now let's continue ...
C # data types
WikipediaThe data type (the term data type is also found) is the fundamental concept of the theory of programming. The data type defines 1) a set of values, 2) a set of operations that can be applied to such values, and possibly 3) a way to implement the storage of values ​​and the execution of operations. Any data that programs operate on is of a specific type.
C # is a hard-typed language. When using it, you must declare the type of each object you are creating (for example, integers, floating-point numbers, strings, windows, buttons, etc.), and the compiler will help you to avoid errors associated with assigning variables to only the type that fits them. The type of an object indicates to the compiler the size of the object (for example, an object of type int occupies 4 bytes in memory) and its properties (for example, the form can be visible and invisible, etc.).
To better understand what they are for, I will give an example. Type is the same grade. For example, a grade of apples. An apple of one sort may be big, contain n iron and be red, and the other grade be small and be violet =)
C # also divides types into two other categories:
dimensional and
reference .
Built-in types
C # provides a programmer with a wide range of built-in types. They all comply with the CLS (Common Language Specification) and this ensures that objects created in C # can be successfully used along with objects created in any other programming language that supports .NET. Each type has a strictly specified size for it, which cannot be changed.
Let's look at the table of built-in types:

In the first column is the name of the type, then the range of values ​​(from how many to how many) and finally the size.
Conversion of built-in types
Objects of one type can be converted to objects of another type implicitly or explicitly. Implicit conversions happen automatically, the compiler does it for you. Explicit conversions are performed when you “cast” a value to another type. Implicit conversions also ensure that data is not lost. For example, you can implicitly cast from short (2 bytes) to int (4 bytes).
Again a small example. Let we have a bucket and a cup. =) If we pour water from a cup into a bucket, then we get an “implicit conversion”, and if we pour it from a bucket into a cup, then only “explicitly”. But how is it possible? We just have all the rest of the water will pour out.
No matter what value is in short, it will not be lost when converting to an int:
short x = 1; int = ; //
short x = 1; int = ; //
If you do the inverse transform, then of course you may lose the information. If the value in int is greater than 32.767, it will be truncated during conversion. The compiler will not perform an implicit conversion from int to short:
- short x;
- int y = 5;
- x = y; // do not compile
You must perform an explicit conversion using the cast operator:
- short x;
- int y - 5;
- x = ( short ) y; // And now everything is OK
Types by reference
Object type
In C #, the object type is the original ancestor type for all types. The object reference can be used to bind to any object. It is also useful in reflection, when the code should work with objects whose type is not known.
Object provides us with some great methods.
Equals () ,
GetHashCode () ,
GetType () and
ToString () . These methods are available to any object and we will talk about them later.
Type string
C # has its own string type. Therefore, operations such as copying and merging happen instantly.
- string s1 = "Hello," ;
- string s2 = "Habra" ;
- string s3 = "habr!" ;
- string s4 = s2 + s1 + s3;
- Console .WriteLine (s4); // => Hello, Habrahabr!
Although the assignment occurs in the style of types by value, the type System.String is a type by reference. By the rows, we will come back!
Variables
A variable is the location in the memory of an object of a particular type. In the examples above, x and y are variables. Variables can have values ​​with which they are initialized, or these values ​​can be changed programmatically.
To create a variable, you must specify the type of the variable and then give the type a name. You can initialize a variable during its declaration or assign a new value to it during program execution. Here is an example of a program that in the first case uses initialization to assign a value to a variable, in the second case uses the assignment of a value to a variable using the “=” operator:
- class variable
- {
- static void Main ()
- {
- int myInt = 10;
- System. Console .WriteLine ( "Initialized variable myInt:" + myInt);
- myInt = 5;
- System. Console .WriteLine ( "Variable myInt after assigning a value:" + myInt);
- Console .ReadLine ();
- }
- }
The result of this program will be as follows:
Initialized mylnt variable: 10
myInt after setting the value: 5
Here is the line:
int myInt = 10;
means the declaration and initialization of the mylnt variable. Line:
myInt = 5;
means setting mylnt to 5.
C # requires the definition of values, that is, variables must be initialized before use. To test this rule, consider the following example:
- class variable
- {
- static void Main ()
- {
- int myInt;
- System. Console .WriteLine ( "Uninitialized variable myInt:" + myInt);
- myInt = 5;
- System. Console .WriteLine ( "After assigning the variable myInt:" + myInt);
- }
- }
If you try to compile this example, the compiler will display the following error message:
error CS3165: Use of unassigned local variable 'mylnt'
You cannot use an uninitialized variable in C #!Or maybe try?
So let's write a small program. What will she do? Print a brief dossier per person:
- using System;
- class first
- {
- string country, city;
- string name = "Vasya Pupkin" ;
- int old, num;
- old = 12;
- num = 666;
- country = "Russia" ;
- city ​​= "Our" ;
- Console .WriteLine ( "Name:" + name);
- Console .WriteLine ( "Age:" + old);
- Console .WriteLine ( "Accommodation Location:" + country + city);
- Console. WriteLine ( "/ n / t Serial Number:" + num);
- Console .ReadLine ();
- }
First comes the declaration of variables and initialization. Following is the output of these variables. On line 17, you met two new characters for you. This is / n and / t. The first one serves to transfer the corset to a new line, and the second one uses the tab character. Below is a table of characters you can use.

On line 18, we added Console.ReadLine () - this is done so that after starting the program the console does not close.
That's all for today.
PS Just found an interesting link for someone.
C # for geeks. (MSDN)