Does Visual Studio have a restricted area for debugging ?!

Source: Internet
Author: User
Debugging a section of my colleague today Code When I found a piece of code debugging, how can I not get into it? Is it possible to encounter the debugging Restricted Area of Visual Studio?

The simplified code is as follows: Class Program
{
Static   Void Main ( String [] ARGs)
{
Simpleclass= NewSimpleclass ();
StringMystring=Simpleclass. onefield;
}
}

Public   Class Simpleclass
{
Private   String _ Onefield =   String . Empty;

Public   String Onefield
{
Get
{
If (_ Onefield. Length =   0 )
{
_ Onefield=Getmystring ();
}

Return _ Onefield;
}
}

Private   String Getmystring ()
{
Return "Just for test ~";
}
}

The line of code that cannot be debugged is "_ onefield = getmystring.

You can debug it on your own and find that the variable _ onefield is always assigned a value inexplicably, but clearly we haven't assigned it a value ......

After the discussion with colleagues, I still did not reach a clear conclusion, but I guess it may be because Visual Studio automatically scans the attributes of the object during debugging and then runs the get operation on its own ~

I don't know if you have encountered this situation. Although the onefield attribute is eventually rewritten as a function to solve this problem, it is still a bit uncomfortable. Is there really no way to debug the above Code in Visual Studio?

Updated conclusion:
After your feedback, I have retried it multiple times and summarized it as follows. You are welcome to give feedback --
To reproduce the problem above, follow these steps: Add a breakpoint to the line "simpleclass = new simpleclass ();", and thenLine-by-line debuggingAnd (please note that this is very important. I believe that many of my brothers and I have different debugging results, probably because of this), to meet any of the following conditions:
1. The Autos window is opened during debugging.
2. Add simpleclass. onefield to watch.
3. Run "simpleclass. when secondfield = "me"; "is displayed, move the cursor to the" simpleclass "object, click" + "in the displayed information display layer, and view the attribute values of the" simpleclass "object.Well, this operation serves the same purpose as opening the Autos window)
In the end, the row "_ onefield = getmystring ();" cannot be reached;

Further Update:
I thought the problems found above would not affectProgramThe running result, but it is unexpectedly discovered that sometimes it will affect the final running result of the program --

The Code is as follows: Class Program
{
Static   Void Main ( String [] ARGs)
{
Simpleclass =   New Simpleclass ();
Simpleclass. secondfield =   " Me " ;
String Mystring = Simpleclass. onefield;
Console. writeline (mystring );

Console. Read ();
}
}

Public   Class Simpleclass
{
Private   String _ Onefield =   String . Empty;
Private   String _ Secondfield =   String . Empty;

Public   String Onefield
{
Get
{
If (_ Onefield. Length =   0 )
{
_ Onefield=Getmystring ();
}

Return _ Onefield;
}
}

Public   String Secondfield
{
Get   {Return_ Secondfield ;}
Set   {_ Secondfield=Value ;}
}

Private   String Getmystring ()
{
Return "Secondfield:" +Secondfield;
}
}

The correct output of the above Code should be: "secondfield: Me ".

But if we do this in debugging...
Well, we can start line-by-line debugging from "simpleclass = new simpleclass ();" and run the line "simpleclass. secondfield =" me (Note that you must perform the following operations before running "simpleclass. secondfield =" me ";"), Move the cursor over the object "simpleclass", click "+" in the pop-up information display layer, and check the attribute values of the "simpleclass" object. Then, OK, F5, you will find that the final output is "secondfield :"!!!

The best solution so far:
Options-> debugging-> General-> enabled property evaluation and other implicit function CILS
Remove the selected status of this option!
Then, all the above problems can be solved-the world is finally quiet ......

Thank you, Q. yuyun!

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.