80 likes | 212 Views
Getting Started with C#. August 29, 2005. .NET Concepts. Language Independence Language Integration your C# program can use a class written in VB Program are compiled into "assemblies" of "microsoft intermediate language" code
E N D
Getting Started with C# August 29, 2005
.NET Concepts • Language Independence • Language Integration • your C# program can use a class written in VB • Program are compiled into "assemblies" of "microsoft intermediate language" code • When a program is run, the IL is compiled into machine code by the Just-In-Time compiler
Some Features of C# • Completely Object-Oriented • even main() must be part of a class • Syntax is very similar to C++ • for loops and comments are the same • IO is different • Garbage collection is automatic • Strongly Typed • Variables must be initialized before their use
Hello World - 1.0 class Class1 { static void Main() { System.Console.WriteLine("Hello World"); } }
Hello World - 1.1 #region Compiler Directives using System; #endregion namespace Test2 { class MainProgram { static void Main() { DateTime today = DateTime.Now; // sample variable Console.Write("Hello, "); Console.WriteLine("Today is {0}/{1}/{2}", today.Month, today.Day, today.Year); } } }
Hello World - 1.1 Allows the editor to compress this code into a single line #region Compiler Directives using System; #endregion namespace Test2 { class MainProgram { static void Main() { DateTime today = DateTime.Now; // sample variable Console.Write("Hello, "); Console.WriteLine("Today is {0}/{1}/{2}", today.Month, today.Day, today.Year); } } } less typing required, but System.Console is not legal Just in case another class is named MainProgram Print the value of a variable Declaration and Initialization the Month property of the today instance Just like C++
Using MS Visual Studio • Open MS Visual Studio .NET via the Start menu • Open a new project • select both "C#" and "Console Application" • rename the project to something such as "lab01" • hit "OK" • Get rid of all the junk the editor added for you • string[] args • etc… • Enter your source code • To compile: Build -> Build Solution • To run: Debug -> Start without Debugging