我有 
a.cs
b.cs我想在 b.cs 调用 a.cs , 该 怎么弄?
在未编译时调用...

解决方案 »

  1.   

    ClassB  c1 = new ClassB();
      

  2.   

    直接a myAA=new a();类得是public 的...
      

  3.   

    ....貌似不行, 把原文件发上来吧...
    我想在 gallery.cs 中调用  a.csgallery.cs
    using System;
    using System.Web;
    using System.IO;
    using System.Text.RegularExpressions;
    //a t=new a();/*-----------------------------------------------------------------------------------*\
     * shawl.qiu c# .net Gallery class v1.0
    \*-----------------------------------------------------------------------------------*/
    //---------------------------------------------------------------------begin class Gallery
    public class Gallery
    {
     //-----------------------------------begin event
     public Gallery()
     {
     }
     
     ~Gallery()
     {
     }
     //-----------------------------------end event
     
     //-----------------------------------begin public constant
     //-----------------------begin about
     public const String auSubject="shawl.qiu c# .net Gallery class";
     public const String auVersion="v1.0";
     public const String au="shawl.qiu";
     public const String auEmail="[email protected]";
     public const String auBlog="http://blog.csdn.net/btbtd";
     public const String auCreateDate="2007-2-5";
     //-----------------------end about
     //-----------------------------------end public constant
     
     //-----------------------------------begin private constant
     //-----------------------------------end private constant
     
     //-----------------------------------begin public static method
     //-----------------------------------end public static method
     
     //-----------------------------------begin private static method
     //-----------------------------------end private static method
     
     //-----------------------------------begin public variable
     public String Path="/images/";
     public String ThumbFolder="thumb";
     public String ShowExtension=".jpg|.jpeg|.gif|.png";
     //public Strin
     //-----------------------------------end public variable
     
     //-----------------------------------begin public method
     public void Go()
     {
      //--------------------------------检测指定的图片路径是否存在
      Path_Phs=System.Web.HttpContext.Current.Server.MapPath(Path);
      if(!Path_Phs.EndsWith("\\"))
      {
       Path_Phs+="\\";
      }
      if(!Directory.Exists(Path_Phs))
      {
       System.Web.HttpContext.Current.Response.Write(WordGallery.PathNotExists);
       PathExists=false;
       goto End;
      }
      
      //--------------------------------设置 缩略图 文件夹
      ThumbFolder_Phs=Path_Phs+ThumbFolder;
      if(!ThumbFolder_Phs.EndsWith("\\"))
      {
       ThumbFolder_Phs+="\\";
      }
      if(!Directory.Exists(ThumbFolder_Phs))
      {
       Directory.CreateDirectory(ThumbFolder_Phs);
      }
      
      //---------------------------------遍历指定目录所有文件
      String[] CurrentPathFiles=Directory.GetFiles(Path_Phs);
      for(Int32 i=0, j=CurrentPathFiles.Length; i<j; i++)
      { 
       String path=CurrentPathFiles[i];
       String ext=System.IO.Path.GetExtension(path)+"";
       
       //--------------------------------检测是否显示该类型
       if(RegexTest(ShowExtension, ext))
       {
        String fileName=System.IO.Path.GetFileName(path);
        String thumbFileName=ThumbFolder_Phs+fileName;
        
        // 缩略图文件夹不存在某文件的缩略图
        if(!File.Exists(thumbFileName))
        {
         System.Web.HttpContext.Current.Response.Write("<li/>file not exists");
         
        }
       }
      } // end for
      
      End:;
     }
     //-----------------------------------end public method
     
     //-----------------------------------begin private variable
     private String Path_Phs="";
     private Boolean PathExists=true;
     private String ThumbFolder_Phs="";
     //-----------------------------------end private variable
     
     //-----------------------------------begin private method
     private Boolean RegexTest(String input, String pattern)
     {
      if(Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase))
      {
       return true;
      }
      return false;
     }
     //-----------------------------------end private method
     
     //-----------------------------------begin public property
     //-----------------------------------end public property
      
     //-----------------------------------begin private property
     //-----------------------------------end private property
    }
    //---------------------------------------------------------------------end class Gallerypublic class WordGallery
    {
     public static String PathNotExists="<h2>指定的路径不存在, 操作被终止...</h2>";
    }
      

  4.   

    a.csusing System;
    //System.Web.HttpContext.Current.Response.Write("");/*-----------------------------------------------------------------------------------*\
     * shawl.qiu class v
    \*-----------------------------------------------------------------------------------*/
    //---------------------------------------------------------------------begin class a
    public class a
    {
     //-----------------------------------begin event
     public a()
     {
     }
     
     ~a()
     {
     }
     //-----------------------------------end event
     
     //-----------------------------------begin public constant
     //-----------------------begin about
     public const String auSubject="";
     public const String auVersion="v1.0";
     public const String au="shawl.qiu";
     public const String auEmail="[email protected]";
     public const String auBlog="http://blog.csdn.net/btbtd";
     public const String auCreateDate="2007-1-25";
     //-----------------------end about
     //-----------------------------------end public constant
     
     //-----------------------------------begin private constant
     //-----------------------------------end private constant
     
     //-----------------------------------begin public static method
     //-----------------------------------end public static method
     
     //-----------------------------------begin private static method
     //-----------------------------------end private static method
     
     //-----------------------------------begin public variable
     //-----------------------------------end public variable
     
     //-----------------------------------begin public method
     //-----------------------------------end public method
     
     //-----------------------------------begin private variable
     //-----------------------------------end private variable
     
     //-----------------------------------begin private method
     //-----------------------------------end private method
     
     //-----------------------------------begin public property
     //-----------------------------------end public property
      
     //-----------------------------------begin private property
     //-----------------------------------end private property
    }
    //---------------------------------------------------------------------end class a
      

  5.   

    其他 .cs(未编译) 
    动态编译 .Net中有类实现
    参见using System.CodeDom.Compiler;
    具体可以去CodeProject找
      

  6.   

    注意是否在一个名词空间里头!还要看权限的问题,是否是PUBLIC的权限,这样才能保证NEW出来可以被调用