App_Code文件夹的使用

of327796068 2010-10-21 02:55:32
为什么创建App_Code文件夹里的类的对象的时候显示找不到类型或命名空间名称??


是先添加App_Code文件夹,然后右点文件夹选添加新项,然后选类是么?
...全文
307 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
hookyzlr 2010-10-21
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wuyq11 的回复:]
public class Class1
{
}
[Serializable]
public class TextInfo
{
public string MathExpression = "";
public int Answer = 0;
}
[Serializable]
public class HistoryTextInfo
{
……
[/Quote]
正解
beyond_me21 2010-10-21
  • 打赏
  • 举报
回复
namespace Class1
{

[Serializable]
public class TextInfo
{
public string MathExpression = "";
public int Answer = 0;
}
[Serializable]
public class HistoryTextInfo
{
public int Textcount = 0;
public int CorrectTextcount = 0;
}


}
用的时候using Class1
of327796068 2010-10-21
  • 打赏
  • 举报
回复
可以了~谢谢各位~刚学这门课~很多不是很懂~~~
tingting74998 2010-10-21
  • 打赏
  • 举报
回复
APP_CODE里的方法最好用静态类,这样其他地方可以直接用。
of327796068 2010-10-21
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 louisit 的回复:]
为什么创建App_Code文件夹里的类的对象的时候显示找不到类型或命名空间名称?? 你有没有 using 引用
是先添加App_Code文件夹,然后右点文件夹选添加新项,然后选类是么? 对
[/Quote]

用的时候要先using哪个命名空间么?

怎么写的?
wuyq11 2010-10-21
  • 打赏
  • 举报
回复
public class Class1
{
}
[Serializable]
public class TextInfo
{
public string MathExpression = "";
public int Answer = 0;
}
[Serializable]
public class HistoryTextInfo
{
public int Textcount = 0;
public int CorrectTextcount = 0;
}
of327796068 2010-10-21
  • 打赏
  • 举报
回复
App_Code文件夹里的类是这样的:


using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
///Class1 的摘要说明
/// </summary>
public class Class1
{

[Serializable]
public class TextInfo
{
public string MathExpression = "";
public int Answer = 0;
}
[Serializable]
public class HistoryTextInfo
{
public int Textcount = 0;
public int CorrectTextcount = 0;
}


}


然后网页的代码页面里有2个字段创建App_Code文件夹里的类的对象:

private TextInfo curText = null;
private HistoryTextInfo scoreInfo = null;


但是提示TextInfo和HistoryTextInfo找不到类型或命名空间名称。


不知道哪里错了?是不是App_Code里的类写错了?
louisit 2010-10-21
  • 打赏
  • 举报
回复
为什么创建App_Code文件夹里的类的对象的时候显示找不到类型或命名空间名称?? 你有没有 using 引用
是先添加App_Code文件夹,然后右点文件夹选添加新项,然后选类是么? 对
  • 打赏
  • 举报
回复
首先程序默认。 WebSite 新建 文件夹下才有选项 App_code(系统文件夹)
WebApplication 新建文件夹 默认无app_code 选项。(如果强制改名文件夹为App_code 也会识别)

App_code 文件夹 主要存放一些 页面通用的赋值类。
里面的 类 和普通的类 一样
whb147 2010-10-21
  • 打赏
  • 举报
回复
[Quote=引用楼主 of327796068 的回复:]
为什么创建App_Code文件夹里的类的对象的时候显示找不到类型或命名空间名称??


是先添加App_Code文件夹,然后右点文件夹选添加新项,然后选类是么?
[/Quote]

不知道你报什么错?
孟子E章 2010-10-21
  • 打赏
  • 举报
回复


是类里面提示的吗?添加相应的引用

另外,WebApplication工程无需创建App_coe
CODE163 2010-10-21
  • 打赏
  • 举报
回复
理论上你在WEBSITE项目中创建的类默认是自由类,自由类是没有命名空间束缚的并不需要通过命名空间引用,而且默认保存在APP_CODE文件夹中。
koukoujiayi 2010-10-21
  • 打赏
  • 举报
回复
[Quote=引用楼主 of327796068 的回复:]

是先添加App_Code文件夹,然后右点文件夹选添加新项,然后选类是么?
[/Quote]
完全正确!

62,272

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧