Vistual studio 2008的一个很有意思的'Bug'
2009-11-04 16:07 宗哥 阅读(3981) 评论(73) 编辑 收藏 举报申明:这个不是C#的bug,觉得是IDE的一个bug,至少这种命名方式在工程中也比较常见,用this可以区分参数和类成员的问题,另外用变量命名方式也可以解决,这种情况我也向学生解释了如果不加this是遵循就近原则。所以不要在攻击我了。不要攻击我,也不要攻击我的学生,^_^.我只是讨论这个算不算IDE的bug问题。
最近有学生问我,对象的字段值竟然自己会变,我觉得不可能,于是她演示代码给我看:
呵呵,有点意思,代码如下:
































先不管代码意义如何,毕竟是学生用来练习构造方法和属性和字段的,下面是调用代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Student s = new Student(20,"徐晋丽");
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Student s = new Student(20,"徐晋丽");
}
}
}
,有趣的现象出现了,请注意字段的浮动值:
代码并没有给这个对象的字段赋值,学生问我问什么字段name的值也是“徐晋丽”?我也奇怪,呵呵,学生真有意思,这个细节也注意到了。
我打开即时编译窗口,如下截图:请注意即使窗口的和开发窗口的值:
呵呵,我只能告诉学生说,这个是微软开发环境的Bug了。变量感知功能的值是假的,对象的实际的值在即使窗口可以看出来并没有编化。看来刘谦也曾经在微软的Vistual Studio部门呆过.
另外提醒她说,可以注意编程规范,尽量避免参数和字段名字或者属性名字一样,如果一样的化,参数访问就近原则,如果要访问类的参数的化,用this就好了。
替这个学生牛角尖的精神感动.......
声明: 本文作者:宗哥,宗子城
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明。 ...
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验