[英]Convert the code in PHP to C#
什么是php中包含函數的C#等效項?我必須將php中的以下代碼轉換為C#
if (file == "") file = str_replace(" ", "", family).strtolower(style) + " +ok sir php";
if (defined("FPDF_FONTPATH"))
file = FPDF_FONTPATH + file;
include(file);
C#中沒有等效項-您不能動態地將文件包含到源代碼中。
在C#中重用代碼的方法是使用控件。 在詢問PHP時,我假設您是指ASP.NET,而不是Winforms或WPF,因此您將需要創建可在網站中重用的用戶控件或自定義控件 。
我曾經用來“包含”另一台服務器的菜單文件的一些代碼。
if (Application["menu"] != null)
{
litMenu.Text = Application["menu"].ToString();
}
else
{
try
{
System.Net.WebRequest wrq = System.Net.WebRequest.Create(ConfigurationManager.AppSettings["MenuPath"]);
System.Net.WebResponse wrp = wrq.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(wrp.GetResponseStream());
litMenu.Text = sr.ReadToEnd();
Application["menu"] = litMenu.Text;
}
catch
{
Application["menu"] = litMenu.Text;
}
}
目的是使我們的Intranet(PHP)和管理后端(ASP.NET)看起來像一個系統。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.