Pages

Monday, 20 June 2011

3. C# Tools

3. C# Tools
This section explores some of the tools provided with the .NET SDK that
can improve your C# programming productivity.
Visual Studio .NET  
Microsoft provides an IDE for fast and productive development with C#. Visual  Studio  .NET  is  an  IDE  for  doing  .NET  development  with  Visual Basic, Visual  C++, and  C#.  Figure  2.1  shows  the  start  screen  of  Visual Studio .NET.

          2.1 Microsoft Visual Studio .net Startup Screen

Typically, IDEs are helpful when you have a lot of files to compile, and so you would group them into projects. Therefore, let's start a new project.  

Step 1  
Click on the New menu option under the File menu item.  
Step 2

Click  on  the  Project  submenu  option.  You  will  see  a  dialog  box  (Figure 2.2). Select the Visual C# option on the left side. On the right side you will

figure 2.2 dilog box showing types of Project
                         see several kinds of applications that you can create using the IDE.Click on Console Application.  
Step 3

Type  the  name  of  your  new  project  in  the  Name  textbox, and  type  the name  of  the  location  where  you  want  to  create  the  new  project.  For  this example, type  Project1  for  the  name, and  type  C:\WorkingFolder  for  the
location. Figure 2.3 shows what you see next.

       figure 2.3 Templet for a console application


Step 4

The  IDE  creates  a  template  class  that  you  can  modify.  The  class  file  is named  Class1.cs. This name is not very intuitive, so save the file as  Hello.cs and  delete  the  Class1.cs  file  from  the  C:\WorkingFolder\Project1  directory.
Now change the name of the class to Hello. It is not necessary that the class name be the same as the file name, but as you will realize when you have large  projects  with  lots  of  files, it's  easier  to  associate  classes  with  files  if each file has only one class with the same name.

Step 5  
The comments that you see above the class definition and the Main method are the C# equivalent of the Javadoc documentation file. This file is XML- based.  Remove  the  TODO  comment  from  the  body  of  the  Main  method.
Type the following line inside the Mainmethod's body:

Console.WriteLine("Hello");
The final screen looks something like Figure 2.4.




While typing the text in the window, you may notice pop-up boxes. This is  the  Visual  Studio  IntelliSense  feature, which  shows  you  the  syntax  of the construct as you are typing it.

Step 6

Now save your project by clicking on File and then Save All.



Behind the scenes, all your project details are stored in an XML file called Project1.csproj.  If  you  open  the  file  using  WordPad, you  will  notice  that the various project files are listed. The IDE also creates an AssemblyInfo.cs file  that  essentially  is  a  programmable  instruction  set  for  deploying  the project.  We  will  also  discuss  the  IDE  when  it  comes  time  to  create  new types  of  applications, such  as  class  libraries, Webforms, Windows applications, and so on.


3.2 The Intermediate Language Disassembler  

The Intermediate Language Disassembler (ILDASM) can do the following: 

    Open an assembly

    Show all types in an assembly

    Show  the  methods  defined  for  those  types  and  the  IL  (Intermediate

Language) that was generated for those methods



To see the IL code generated for MySample.1.cs, you open the MySample.1.EXE file using the ildasm executable. The  ildasm executable can be found in the following path: 

C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin  

If you have trouble finding the file, just do a search on the file name. 
After you  start the  ILDASM  tool,  click  on  File  and  then  Open.  Select  the EXE  file  you  want  to  view.  The  tool  then  displays  the  EXE  file  in  a  tree format.  To  see  the  IL  of  the  individual  tree  components, highlight  the component and then press Enter. Alternatively, you can do a tree dump of the file in an IL file. Click on File and then Dump. A dialog box pops up asking to save the dump in an IL file. Save the details in the Project1.il file.  The ILDASM can be called on the command line, too. Figure 2.6 shows the details of the Project1.IL file without the comments.

No comments:

Post a Comment

Thanks For your Comments Please Continue with your precious Time and greate Knowladge will be benificial for learner like me thanks a lot...........