FREE BOOK

Writing Windows C# Programs

Posted by Addison Wesley Free Book | C# Language July 21, 2009
The C# language has its roots in C++, Visual Basic, and Java. Both C# and VB.Net use the same libraries and compile to the same underlying code. Both are managed languages with garbage collection of unused variable space, and both can be used interchangeably. Both also use classes with method names that are very similar to those in Java, so if you are familiar with Java, you will have no trouble with C#.
 

Writing Windows C# Programs
 
The C# language has its roots in C++, Visual Basic, and Java. Both C# and VB.Net use the same libraries and compile to the same underlying code. Both are managed languages with garbage collection of unused variable space, and both can be used interchangeably. Both also use classes with method names that are very similar to those in Java, so if you are familiar with Java, you will have no trouble with C#.
 
Objects in C#
 
In C#, everything is treated as an object. Objects contain data and have methods that operate on them. For example, strings are now objects. They have methodssuch as these.

  • Substring
  • ToLowerCase
  • ToUpperCase
  • IndexOf
  • Insert

Integers, float, and double variables are also objects, and they have methods.

            string s;
            float x;
            x = 12.3;
            s = x.ToString();

Note that conversion from numerical types is done using these methods rather than external functions. If you want to format a number as a particular kind of string, each numeric type has a Format method.

Managed Languages and Garbage Collection

C# and VB.Net are both managed languages. This has two major implications. First, both are compiled to an intermediate low-level language, and a common language runtime (CLR) is used to execute this compiled code, perhaps compiling it further first. So, not only do C# and VB.Net share the same runtime libraries, they are to a large degree two sides of the same coin and two aspects of the same language system. The differences are that VB7 is more Visual Basic–like and a bit easier for VB programmers to learn and use. C# on the other hand is more C++- and Java-like and may appeal more to programmers already experienced in those languages.

The other major implication is that managed languages are garbage-collected. Garbage-collected languages take care of releasing unused memory. (You never have to be concerned with this.) As soon as the garbage-collection system detects that there are no more active references to a variable, array, or object, the memory is released back to the system. Of course, it is still possible to write memory-eating code, but for the most part, you do not have to worry about memory allocation and release problems.

Total Pages : 6 12345
COMMENT USING
PREMIUM SPONSORS
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.