【问题标题】:Is the Format of my ASP.NET C# Script Ok?我的 ASP.NET C# 脚本的格式可以吗?
【发布时间】:2013-02-06 17:42:51
【问题描述】:

C# 新手我在一个名为“PageFlex”的程序的结构中工作,该程序的所有结构都放在下面的代码中。我在此处发布此内容的主要原因是确保我正确格式化了我的脚本。如果这看起来格式正确,请告诉我。 还有像 jsfiddle.net 这样的网站可以用于 C# 吗?

<script language="C#" runat="server">

string GetUserID(Pageflex.Ur.Storefront.Data.StorefrontAPI isini)
{
    return isini.GetValue("SystemProperty", "LoggedOnUserID", null);
}

int GetShoppingCartCount()
{

    Pageflex.Ur.Storefront.Data.StorefrontAPI isini =
       new Pageflex.Ur.Storefront.Data.StorefrontAPI();
    string userID = GetUserID(isini);
    string[] docsInCart = isini.GetListValue("UserListProperty", "DocumentsInShoppingCart", userID);
    return (docsInCart != null) ? docsInCart.Length : 0;
}
int GetShoppingCartTotal()
{
    Pageflex.Ur.Storefront.Data.StorefrontAPI isini =
    new Pageflex.Ur.Storefront.Data.StorefrontAPI();
    string userID = GetUserID(isini);
    string[] docsTotalPrice = isini.GetListValue("DocumentProperty", "DocumentPrice", userID);
     return (docsTotalPrice != null) ? docsTotalPrice.Length : 0;
}
void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        int documentPrice = GetShoppingCartTotal();
        priceCart.Text = shoppingPrice.ToString();

        int shoppingCount = GetShoppingCartCount();
        numCart.Text = shoppingCount.ToString();
        ItemOrItems.Text = (shoppingCount == 1) ? "item" : "items";
    }
}
</script>

【问题讨论】:

标签: c# asp.net format


【解决方案1】:

在我看来,事情是正确的。您可能需要将您的方法声明为公开的:

 public int GetShoppingCartTotal()
 {
 // logic
 }

但是,当您的代码处于页面级别时,您可能不必这样做。

【讨论】:

  • 它在页面级别只是不想让人们挖掘.. 这很好,至少我正在等待程序论坛对我搞砸了什么的回应。其中一个值不正确。
【解决方案2】:

关于

还有一个类似 jsfiddle.net 的网站可以用于 C# 吗?

你可以随时尝试Ideone(虽然它不完全像 jsfiddle),它支持很多不同的语言,包括 C# (Mono)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-27
    • 1970-01-01
    • 2022-01-08
    相关资源
    最近更新 更多