How to debug your C # program

Source: Internet
Author: User
Tags comments readline

Welcome to the wonderful skies of C #, where you can get what you want. We sincerely hope to bring you great help and bring you into another vast space.

Come on. Follow me and then U can win!

Similar to GDB in the GNU C + + tool under Linux, C # provides a command-line debugger, "Cordbg.exe," which you can easily debug your C # application, and this article will not be able to give you a complete description of CorDbg's functionality, I just want to be able to get something out of you by introducing this article. It's a pleasure for me to be of some help to you. Nonsense or say less!

Cordbd:microsoft (R) Common Language Runtime Test Debugger Shell

I don't define this thing for the time being, we look at it step-by-step:
My machine configuration: Win2K professional+iis 5.0+microsoft. NET Framework SDK (BETA2)
Let's start with a simple program:

Test-1.cs
/*
'Data:2001-12-13
'Author:龙山文化
'FileName:Test-1.cs
'One Csharp Test Program
*/
using System;
class Test_1
{
 static void Main()
 {
  string str;
  Console.WriteLine("Please Enter Your Name. Thanks!");
  str=Console.ReadLine();
  Console.WriteLine("------------------------------------\r\n");
  Console.WriteLine("Dear "+str+", Welcome To Csharp's World!\r\n");
  Console.WriteLine("------------------------------------\r\n");
 }
}

The above program is extremely simple, and I'm going to use a more complicated example to debug it later in the article. Let's start with a step-by-step!
Note, however, that I use "/* ... * *" to mark notes and some related text.
Start-> run->cmd,ok, now open a DOS window, compile your C # program. (All of the following input actions are a whole debugging process, please be careful not to confuse the comments I add to the back.) Also, please follow the color to determine the data that I entered, those are the data that the computer outputs.

Debug Start:
First step: Compile the above program
E:\cs>csc/debug test-1.cs
/* Notice that I'm compiling this test-1.cs with the "Debug" argument (this debug parameter Keep your old self diligent and look at MSDN, and if there's nothing wrong, let's continue. Need to remind you that some users of the system path does not specify the location of Csc.exe, in the Run "Csc.exe", may not be able to find, at that time you must specify the Csc.exe path, such as my Csc.exe path is: "E:\ Program Files\microsoft.net\frameworksdk\bin\cordbg.exe "That's a bit of nonsense because sometimes you can't call this thing directly on a computer that has VS7 (Beta 2) installed.
After compiling, check your file path with Dir, except for one more Test-1.exe and another test-1.pdb, which is a document that stores debugging information.
*/
Step two: Load your program (the following is the information you have on the system output after you load a program)

E:\Cs>Cordbg Test-1.exe
Microsoft (R) Common Language Runtime Test Debugger Shell.
Version 1.0.2914.16 Copyright (C) Microsoft Corp. 1998-2001. All rights reserved
.
(cordbg) run Test-1.exe
Process 22952/0x59a8 created.
Warning: couldn't load symbols for c:\winnt\microsoft.net\framework\v1.0.2914\ms
corlib.dll
[thread 0x59a4] Thread created.
012: Console.WriteLine("Please Enter Your Name. Thanks!");
(cordbg)
/* 装载程序还有另外一种方法,我将在以后的文档中加以说明。*/

Step three: Debug your program; (the following will be the time to debug the program all the code, please note that my comments are added to the back)

(cordbg)sh 18
001: /*
002: 'Data:2001-12-13
003: 'Author:龙山文化
004: 'One Csharp Test Program
005: */
006: using System;
007: class Test_1
008: {
009: static void Main()
010: {
011: string str;
012:* Console.WriteLine("Please Enter Your Name. Thanks!");
013: str=Console.ReadLine();
014: Console.WriteLine("------------------------------------\r\n");
015: Console.WriteLine("Dear "+str+", Welcome To Csharp's World!\r\n");
016: Console.WriteLine("------------------------------------\r\n");
017: }
018: }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.