在 .cs 文件中, 怎么调用 其他 .cs(未编译)

btbtd 2007-02-05 04:30:22
我有
a.cs
b.cs

我想在 b.cs 调用 a.cs , 该 怎么弄?
在未编译时调用...
...全文
292 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
btbtd 2007-02-05
  • 打赏
  • 举报
回复
谢谢各位, 我把文件放在一个 .cs 里了, 问题解决...
qu882618520 2007-02-05
  • 打赏
  • 举报
回复
注意是否在一个名词空间里头!还要看权限的问题,是否是PUBLIC的权限,这样才能保证NEW出来可以被调用
Red_angelX 2007-02-05
  • 打赏
  • 举报
回复
其他 .cs(未编译)
动态编译 .Net中有类实现
参见using System.CodeDom.Compiler;
具体可以去CodeProject找
oldmoon 2007-02-05
  • 打赏
  • 举报
回复
ClassA a=new ClassA();
btbtd 2007-02-05
  • 打赏
  • 举报
回复
a.cs

using 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="shawl.qiu@gmail.com";
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
btbtd 2007-02-05
  • 打赏
  • 举报
回复
....貌似不行, 把原文件发上来吧...
我想在 gallery.cs 中调用 a.cs

gallery.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="shawl.qiu@gmail.com";
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 Gallery

public class WordGallery
{
public static String PathNotExists="<h2>指定的路径不存在, 操作被终止...</h2>";
}
btbtd 2007-02-05
  • 打赏
  • 举报
回复
谢谢, 现在就试试去...
  • 打赏
  • 举报
回复
直接a myAA=new a();类得是public 的...
cpp2017 2007-02-05
  • 打赏
  • 举报
回复
ClassB c1 = new ClassB();
btbtd 2007-02-05
  • 打赏
  • 举报
回复
是在同级目录...

62,243

社区成员

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

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

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

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