by Amy Roberge and John Linehan
Step-by-step instructions for learning to program in C#
About
| Name: | C Sharp |
| Year created: | 2000 |
| Created by: | Microsoft as part of their .NET platform to unite programming languages for web based usage |
| Paradigm: | Object-oriented |
| Platform: | Requires the .NET platform to run |
| Advantages: | Only allows single inheritance, but can implement any number of interfaces, provides a balance of C++, rapid development, Visual Basic, Delphi, and Java, and also has automatic garbage collection |
| Disadvantages: | Requires the .NET Runtime Environment which creates more overhead, does not have true multiple inheritance, and finally, "Unsafe" code is required to manage memory directly and can be very complex and difficult to debug |
| Grammar: | http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec_c.asp |
| Specification: | http://msdn.microsoft.com/vcsharp/programming/language/ |
Step 1. Download & install .NET Framework SDK 1.1
Step 2. Download and install the latest version of SharpDevelop
Step 3. Write a "hello world" program
using System; public class HelloWorld { public static void Main() { Console.WriteLine("HELLO WORLD"); } }
Step 4. Run the "hello world" program
Step 5. Make it Visual
using System; using System.Drawing; using System.Windows.Forms; namespace helloworldvisual { ////// Description of MainForm. /// public class MainForm : System.Windows.Forms.Form { private System.Windows.Forms.Button helloVisible; private System.Windows.Forms.Button quitButton; private System.Windows.Forms.Button helloHide; private System.Windows.Forms.Label helloLabel; public MainForm() { InitializeComponent(); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } #region Windows Forms Designer generated code ////// private void InitializeComponent() { this.helloLabel = new System.Windows.Forms.Label(); this.helloHide = new System.Windows.Forms.Button(); this.quitButton = new System.Windows.Forms.Button(); this.helloVisible = new System.Windows.Forms.Button(); this.SuspendLayout(); this.helloLabel.Font = new System.Drawing.Font("Tahoma", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.helloLabel.Location = new System.Drawing.Point(16, 40); this.helloLabel.Name = "helloLabel"; this.helloLabel.Size = new System.Drawing.Size(216, 56); this.helloLabel.TabIndex = 1; this.helloLabel.Text = "Hello World"; this.helloLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.helloLabel.Visible = false; this.helloLabel.Click += new System.EventHandler(this.Label1Click); this.helloHide.Enabled = false; this.helloHide.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.helloHide.Location = new System.Drawing.Point(136, 136); this.helloHide.Name = "helloHide"; this.helloHide.Size = new System.Drawing.Size(88, 40); this.helloHide.TabIndex = 2; this.helloHide.Text = "Hide"; this.helloHide.Click += new System.EventHandler(this.HideClick); this.quitButton.Font = new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.quitButton.Location = new System.Drawing.Point(24, 184); this.quitButton.Name = "quitButton"; this.quitButton.Size = new System.Drawing.Size(200, 48); this.quitButton.TabIndex = 3; this.quitButton.Text = "Exit"; this.quitButton.Click += new System.EventHandler(this.QuitButtonClick); this.helloVisible.Font = new System.Drawing.Font("Tahoma", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.helloVisible.Location = new System.Drawing.Point(24, 136); this.helloVisible.Name = "helloVisible"; this.helloVisible.Size = new System.Drawing.Size(88, 40); this.helloVisible.TabIndex = 0; this.helloVisible.Text = "Show"; this.helloVisible.Click += new System.EventHandler(this.HelloVisibleClick); this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(248, 240); this.Controls.Add(this.quitButton); this.Controls.Add(this.helloHide); this.Controls.Add(this.helloLabel); this.Controls.Add(this.helloVisible); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Hello World Graphics"; this.Load += new System.EventHandler(this.MainFormLoad); this.ResumeLayout(false); } void Label1Click(object sender, System.EventArgs e) { } void HelloVisibleClick(object sender, System.EventArgs e) { helloLabel.Visible = true; helloVisible.Enabled = false; helloHide.Enabled = true; } void HideClick(object sender, System.EventArgs e) { helloLabel.Visible = false; helloHide.Enabled = false; helloVisible.Enabled = true; } void QuitButtonClick(object sender, System.EventArgs e) { MainForm.ActiveForm.Close(); } void MainFormLoad(object sender, System.EventArgs e) { } } }
Step 6. Learn More About C#