繁体   English   中英

我的ASP.NET C#脚本的格式可以吗?

[英]Is the Format of my ASP.NET C# Script Ok?

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>

事情对我来说似乎正确。 您可能需要将您的方法声明为public:

 public int GetShoppingCartTotal()
 {
 // logic
 }

但是,您不必一定要在页面级别编写代码。

关于

还有像jsfiddle.net这样的网站可用于C#吗?

您可以随时尝试使用Ideone (尽管它并不完全像jsfiddle一样),它支持很多不同的语言,包括C#(Mono)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM