将PHP中的代码转换为C#

时间:2010-02-10 08:25:38

标签: c# php include

什么是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);

2 个答案:

答案 0 :(得分:5)

C#中没有等效内容 - 您无法在源代码中动态包含文件。

在C#中重用代码的方法是使用控件。当您询问PHP时,我认为您的意思是ASP.NET而不是Winforms或WPF,因此您需要创建user controls or custom controls,您可以在您的网站中重复使用。

答案 1 :(得分:0)

我曾经使用某些代码“包含”来自其他服务器的菜单文件。

    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)看起来像是同一个系统。