×

Loading...
Ad by
Ad by

请教大侠,关于C#

我用 visual web developer 2005 express edition 写了一个小的web project. 以前写的时候我把所有的 help class 都放在一起。也就是放在一个file里面。 如果想建立help class object 就直接
用 Class1 c = new Class1(); 就行了。 例子如下

public partial class _Default : System.Web.UI.Page
{
public void test()
{
Class1 c = new Class1();
}
}
//
public class Class1
{

public Class1()
{
}
public String hello1()
{
return "hello";
}
}

但现在我想把help class 分开来 save different file name, 但摆在相同的文件夹里面。 但是C# 老是说 Class1 can not be found. 我在 Class1 外加了namespace. 得到的结果也是 namespace can not be found.

想问一问大侠们, 是不是我那里设置不对.

谢谢
Report

Replies, comments and Discussions:

  • 工作学习 / 专业技术讨论 / 请教大侠,关于C#
    我用 visual web developer 2005 express edition 写了一个小的web project. 以前写的时候我把所有的 help class 都放在一起。也就是放在一个file里面。 如果想建立help class object 就直接
    用 Class1 c = new Class1(); 就行了。 例子如下

    public partial class _Default : System.Web.UI.Page
    {
    public void test()
    {
    Class1 c = new Class1();
    }
    }
    //
    public class Class1
    {

    public Class1()
    {
    }
    public String hello1()
    {
    return "hello";
    }
    }

    但现在我想把help class 分开来 save different file name, 但摆在相同的文件夹里面。 但是C# 老是说 Class1 can not be found. 我在 Class1 外加了namespace. 得到的结果也是 namespace can not be found.

    想问一问大侠们, 是不是我那里设置不对.

    谢谢
    • 把class1的file放到app_code子目录里面
      • 我试了一下, 还是不行, 多谢
        • 谢谢, 行了 需要自己建立一个 App_Code. 刚才我把它放在App_Data 里面了。 有没有什么办法不用放在App_Code 里面 也可以。 我google 了很长时间都没有找到。 真是听君一席话 胜读十年书
          • VS 2005在建web Application时是不编译的,就是你执行编译命令,其实只是执行语法检查。
            但是VS 2005给你一个内建的.Net folder叫App_Code,你将你的Classes都放在这个App_Code里,VS 2005会自动检查语法,如果没错误,VS2005会自动预编译所有的在这个Folder里的Classes。这样你可以在别的页面或Classes里直接调用这些没有语法错误的完成的Classes,你如果放在别的Folders里,VS2005不知道,所以会警告说找不到这些Classes。

            以前的VS2003,你可以将Classes放在别的Folders是因为在执行编译命令时它会真正编译所有在这个project里的Classes。VS2003和VS2005在如何编译Web Application上的行为是不同的。
          • write a different library put it under bin, which is not App_Code, so u get what u want :)
            • 我也试过, 但是就是不方便。 每次change the code, 你都要 re compile the source code to dll file 然后 add reference into bin folder.
              • how come 不方便? that's the way people do large project. you don't have to reference everytime, you reference to the project, not the dll. Everytime you build the solution, the dll will be updated automatically.
                • 大侠, 请问如何加别人的project, 我用的是 visual studio web developer express 2005. 当我加reference 时, 只有 4个tab让我选 1. net 2. com 3. browser 4. recent. 当我选 browser 时 component file 只有 dll tlb olb ocx exe 可选 谢谢
                  • do you have another project in the same solution?
                    • 好像 visual studio 2005 web developer express 2005 里面 好像不能创建solution 和project. folder 里面没有sln 和 proj file
                      • that's why microsoft designs that. to force you feel annoying so that you either buy it or download it :)