我有个文件叫cookie.cs,文件内容如下:
那么我怎么在其他cs文件中调用cookie.cs文件中函数CreateCookieValue?using System.Web;
public partial class cookie : System.Web.UI.Page
 {
  private void CreateCookieValue(string cookieName, string cookieValue, DateTime cookieTime)
    {
    .............
    }
 }

解决方案 »

  1.   

    private void CreateCookieValue(string cookieName, string cookieValue, DateTime cookieTime)把private 改为publiccookie ck = new cookie();
    xxxx=ck.CreateCookieValue(xxx,xxx,xx)'
      

  2.   

    2个东西在不同文件里啊,难道其他文件不需要加using 这个空间一类的代码?
    感觉应该加的,但具体怎么写,我就不知道了.
      

  3.   

    用不用using要看你的这两个类在不在一个命名空间了,如果不在的话需要using
      

  4.   

    声明了partial,不论其他是在哪个文件里面,只要也是cookie类,就应该能直接调用了吧
      

  5.   

    我的2个文件是这样的,为什么在Default2.aspx文件中使用GetStringLength,还是出错呢?
    utils.cs文件内容:
    {
        public class Utils
        {
            public static int GetStringLength(string str)
            {
                return Encoding.Default.GetBytes(str).Length;
            }
        }
    }
    Default2.aspx文件内容
    namespace Ke.Common
    {
        public partial class aspx_Default2 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                int xx = GetStringLength("aaaaa");        }
        }
    }
      

  6.   

    知道了,忘记加类名了。
    应该是
    int xx = Utils.GetStringLength("aaaaa");谢谢各位