Tuesday, October 11, 2011

- Building C# Applications

Visual Studio 2010 Command Prompt
The Visual Studio Command Prompt can be accessed through Start-> All Programs-> Microsoft Visual Studio 2010-> Visual Studio Tools folder
CSC (C-Sharp Compiler) let you compile a source file through command prompt for more info type
csc -?
Visual Studio 2010 Command Prompt

by having following code in a HellowWorld.cs class

using System;

class HelloWorld
{
  static void Main()
  {
    Console.WriteLine("Hello World");
  }
}

It can be compiled by going to corresponding folder by visual studio command prompt and type the following command  "csc HelloWorld.cs" . By doing so "HelloWorld.exe" will be created by compiler and you may execute it to see the output.
Keep in mind if you would like to use windows form (e.g. MeassageBox.Show("Hello World");) in the code you need to add this namespace to your code (using System.Windows.Forms;)
It is good to know by default the csc  use csc.rsp response file located at C:\Windows\Microsoft.NET\FrameWork\<version>. C# response files contain all the instructions to be used during the compilation of your current build. if you wish to ignore the default response file /nonconfig key can be used in this case all the output and necessary reference files(e.g. System.Windows.Forms.dll in order to use windows form) needed to be mentioned manually.
Visual Studio is the IDE to use for writing your application. Here are some more alternatives:
Simple Editor with some extra features: Notebad++ http://notepad-plus-plus.org/
Open Source IDE: SharpDevelop http://www.icsharpcode.net/
Browser based IDE: Coderun (online IDE)  http://www.coderun.com/

Refactoring:
Visual Studio 2010 support refactoring which is really help full to improve existing code.
  • Extract Method: creating new method based on a selection of code statement (Ctrl+R, M)
  • Encapsulate Field: Makes Public field private (Ctrl+R, E)
  • Extract Interface:Defines new interface type based on a set of existing type members (Ctrl+R, I)
  • Reorder Parameters: reorder member arguments (Ctrl+R, O)
  • Remove Parameters: remove argument (Ctrl+R, V)
  • Rename: rename method name, field, local variable and so forth (F2)
    Code Expansion and Surround with:
    • Snippets: These templates insert common code blocks. (right click / Insert Snippets... or Ctrl+K, X)
    • Surround with: These templates wrap a block of selected statements within a relevant scope
    By pressing Tab key twice after part of code is typed and intellisense shows you the desirable code you can activate the snippets. (e.g type sw the intellisense will display switch as below screen shot)
    intellisense

    By pressing Tab key 2 times below block of code will insert to your program
    Snippets
    Snippets will help you to save time and have cleaner code. for more info about snippets visit:

    Class Designer:
    Visual Studio  Class Designer allows you to view and modify the relationships of the types (classes, interfaces, structures, enumerations, and delegates.
    In order to use Class Designer utilities you need to insert a new class diagram file. One way to do that use the Class Diagram button located on Solution Explorer's right side (see below figure) make sure your project is selected not the solution.
    Insert a Class Diagram
    Class Details (View->Other Windows) and Class Designer Toolbox (View -> Toolbox) are tow other aspects of Visual studio 2010 work in conjunction with  Class Diagram.
    Class Details window shows the details of the currently selected item in the diagram and also allows you to modify existing members and insert new members on the fly. Below screen shot shows an example for above explained utilities.
    Class Diagram, Class Details and Class Designer Toolbox
      .NET Framework 4.0 SDK Documentation System:
      The .NET Framework 4.0 SDK documentation provides good, readable and full of information.
      The documentations are available online : http://msdn.microsoft.com/library

      You can add and Install help system locally to your computer through:
      Start-> All Programs-> Microsoft Visual Studio 2010-> Visual Studio Tools -> Manage Help Settings

      Reference: Pro C# 2010 and the .NET 4 Platform by Andrew Troelsen.

      No comments:

      Post a Comment