为什么这个简单的代码不能编译? [英] Why doesn't this simple code compile?

查看:105
本文介绍了为什么这个简单的代码不能编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Team Studio 2005

1.创建一个新网站

2.在项目中添加一个新类

3.在default.aspx.cxs的Page_Load处理程序,创建对

新类的引用

4.编译解决方案

结果:类型或找不到命名空间名称''TestClass''(你是不是
缺少一个using指令或汇编引用?)


例如,这里'' s我的default.aspx.cs:

使用System;

使用System.Data;

使用System.Configuration;

使用System.Web;

使用System.Web.Security;

使用System.Web.UI;

使用System.Web .UI.WebControls;

使用System.Web.UI.WebControls.WebParts;

使用System.Web.UI.HtmlControls;


public partial class _Default:System.Web.UI.Page

{

protected void Page_Load(object sender,EventArgs e)

{

TestClass tc = new q();

}

}


这里是我创建的课程:

使用System;

使用System.Data;

使用System.Configuration;

使用System.Web;

使用System.Web。安全性;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Web.UI.WebControls .WebParts;

使用System.Web.UI.HtmlControls;


///< summary>

/// TestClass的摘要描述

///< / summary>

公共类TestClass

{

public TestClass ()

{

}

}


我使用VB.NET复制了相同的行为。


在Visual Studio 2003中,上面编译的代码在2005年没有。为什么

不是?


谢谢。

using Team Studio 2005
1. Create a new web site
2. Add a new class to the project
3. In the Page_Load handler of default.aspx.cxs, create a reference to the
new class
4. compile solution
Result: The type or namespace name ''TestClass'' could not be found (are you
missing a using directive or an assembly reference?)

For example, here''s my default.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TestClass tc = new q();
}
}

here''s the class I created:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for TestClass
/// </summary>
public class TestClass
{
public TestClass()
{
}
}

I duplicated the same behavior using VB.NET.

In Visual Studio 2003, the above code compiled, in 2005, it does not. Why
not?

Thanks.

推荐答案

HI Roy


你收到了哪些错误信息?

HI Roy

Which error message did you recieve on that code?


对不起罗伊 - 我没有仔细阅读够了

我认为你必须写:

TestClass tc = new TestClass();


你的代码:
Sorry Roy - I didn''t read that carefully enough
For my opinion you have to write:
TestClass tc = new TestClass();

Your code:
TestClass tc = new q();
TestClass tc = new q();



无效 - 编译器如何知道'q()'是什么 - 即使我们

不能:)


希望这有帮助

Roland


is not valid - how can the compiler know what this ''q()'' is - even we
can not :)

Hope this helps
Roland


Roy,


确保页面类和您的类在同一名称空间中

-


Stoitcho Goutsev(100)[C#MVP]


" Roy" < Ro*@discussions.microsoft.com>在消息中写道

news:15 ********************************** @ microsof t.com ...
Roy,

Make sure that the page class and your class are in the same namespace
--

Stoitcho Goutsev (100) [C# MVP]

"Roy" <Ro*@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.com...
使用Team Studio 2005
1.创建一个新网站
2.在项目中添加一个新类
3.在default.aspx.cxs的Page_Load处理程序,创建对
新类的引用
4.编译解决方案结果:找不到类型或命名空间名称''TestClass''(是你没有使用using指令或程序集引用?)

例如,这里是我的default.aspx.cs:
使用System;
使用System .Data;
使用System.Configuration;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System。 Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Web.UI.HtmlControls;

公共部分类_Default:System.Web .UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
TestClas s tc = new q();
}
}
这里是我创建的类:
使用System;
使用System.Data ;
使用System.Configuration;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System.Web。 UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Web.UI.HtmlControls;

///< summary>
/// TestClass的摘要说明
///< / summary>
公共类TestClass
{
公共TestClass()
{
}
}

我使用VB.NET复制了相同的行为。

在Visual Studio 2003中,上面编译的代码在2005年没有。为什么
不是?

谢谢。
using Team Studio 2005
1. Create a new web site
2. Add a new class to the project
3. In the Page_Load handler of default.aspx.cxs, create a reference to the
new class
4. compile solution
Result: The type or namespace name ''TestClass'' could not be found (are you
missing a using directive or an assembly reference?)

For example, here''s my default.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TestClass tc = new q();
}
}

here''s the class I created:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for TestClass
/// </summary>
public class TestClass
{
public TestClass()
{
}
}

I duplicated the same behavior using VB.NET.

In Visual Studio 2003, the above code compiled, in 2005, it does not. Why
not?

Thanks.



这篇关于为什么这个简单的代码不能编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆