【问题标题】:Convert the code in PHP to C#将 PHP 中的代码转换为 C#
【发布时间】:2011-01-15 04:09:46
【问题描述】:

什么是 C# 等效于 php 中的包含函数??我必须将 php 中的以下代码转换为 C#

if (file == "") file = str_replace(" ", "", family).strtolower(style) + " +ok sir php";
if (defined("FPDF_FONTPATH"))
file = FPDF_FONTPATH + file;
include(file);

【问题讨论】:

  • 恐怕唯一的解决办法就是with your bare hands

标签: c# php include


【解决方案1】:

C# 中没有等价物 - 您不能将文件动态包含到源代码中。

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

【讨论】:

    【解决方案2】:

    我用来“包含”另一个服务器的菜单文件的一些代码。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-18
      • 1970-01-01
      • 1970-01-01
      • 2014-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-25
      相关资源
      最近更新 更多