ASP.net MVC 5 C#从IF语句中返回double

ASP.net MVC 5 C#从IF语句中返回double,c#,asp.net,asp.net-mvc,if-statement,double,C#,Asp.net,Asp.net Mvc,If Statement,Double,如何从IF语句中访问double [HttpPost] public ActionResult Iflexcst([Optional] float Quan, [Optional] float kammid, [Optional] float kammod, [Optional] float SpacerInnerDim, [Optional] float SpacerOuterDim, [Optional] float WashOuterDim, [Optional]float Is

如何从IF语句中访问double

 [HttpPost]
    public ActionResult Iflexcst([Optional] float Quan, [Optional] float kammid, [Optional] float kammod, [Optional] float SpacerInnerDim, [Optional] float SpacerOuterDim, [Optional] float WashOuterDim, [Optional]float IsoWashInnerDim, [Optional]float SteelWashInnerDim, [Optional] float SteelWashQuan, [Optional] float IsoWashQuan, FormCollection form)
    {
        //other functions removed
        if (WashOuterDim <= 43.6)
        {

            double washerSerrTime = 0.6;
            double SerrWasherRun = (washerSerrTime * IsoWashQuan) * (1 / 60);
            ViewBag.SerrWasherRun = SerrWasherRun;

            double SerrWasherRunPrice = ((SerrateSetup / Quan) + washerSerrTime) * serrateRate;
            ViewBag.SerrWasherRunPrice = SerrWasherRunPrice;

        }

        if (WashOuterDim > 43.6)
        {


            double washerSerrTime = 0.833;
            double SerrWasherRun = (washerSerrTime * IsoWashQuan) * (1 / 60);
            ViewBag.SerrWasherRun = SerrWasherRun;

            double SerrWasherRunPrice = ((SerrateSetup / Quan) + washerSerrTime) * serrateRate;
            ViewBag.SerrWasherRunPrice = SerrWasherRunPrice;


        }


        // Adds together all costs 
        float Price = (float)SerrWasherRunPrice;
[HttpPost]
公开操作结果IFlexST([可选]浮点数,[可选]浮点数kammid,[可选]浮点数kammod,[可选]浮点数间隔器InnerDim,[可选]浮点数WashOuterDim,[可选]浮点数IsoWashInnerDim,[可选]浮点数WashInnerDim,[可选]浮点数WashQuan,[可选]浮点数IsoWashQuan,FormCollection form)
{
//删除其他功能
如果(第43.6条)
{
双洗衣机错误时间=0.833;
双SerrWasherRun=(洗衣机错误时间*IsoWashQuan)*(1/60);
ViewBag.SerrWasherRun=SerrWasherRun;
双色色板价格=((锯齿设置/全)+洗衣机错误时间)*锯齿率;
ViewBag.SerrWasherRunPrice=SerrWasherRunPrice;
}
//将所有成本加在一起
浮动价格=(浮动)SerrWasherRunPrice;

它建议为“SerrWasherRunPrice”创建获取和设置,或将其作为公共变量,但这两种解决方案都会与另一个声明冲突。

如果

[HttpPost]
public ActionResult Iflexcst([Optional] float Quan, [Optional] float kammid, [Optional] float kammod, [Optional] float SpacerInnerDim, [Optional] float SpacerOuterDim, [Optional] float WashOuterDim, [Optional]float IsoWashInnerDim, [Optional]float SteelWashInnerDim, [Optional] float SteelWashQuan, [Optional] float IsoWashQuan, FormCollection form)
{
    //other functions removed
    double SerrWasherPrice = 0;
    if (WashOuterDim <= 43.6)
    {

        double washerSerrTime = 0.6;
        double SerrWasherRun = (washerSerrTime * IsoWashQuan) * (1 / 60);
        ViewBag.SerrWasherRun = SerrWasherRun;

        SerrWasherRunPrice = ((SerrateSetup / Quan) + washerSerrTime) * serrateRate;
        ViewBag.SerrWasherRunPrice = SerrWasherRunPrice;

    }
   else
    {
        double washerSerrTime = 0.833;
        double SerrWasherRun = (washerSerrTime * IsoWashQuan) * (1 / 60);
        ViewBag.SerrWasherRun = SerrWasherRun;

        SerrWasherRunPrice = ((SerrateSetup / Quan) + washerSerrTime) * serrateRate;
        ViewBag.SerrWasherRunPrice = SerrWasherRunPrice;


    }


    // Adds together all costs 
    float Price = (float)SerrWasherRunPrice;
[HttpPost]
公开操作结果IFlexST([可选]浮点数,[可选]浮点数kammid,[可选]浮点数kammod,[可选]浮点数间隔器InnerDim,[可选]浮点数WashOuterDim,[可选]浮点数IsoWashInnerDim,[可选]浮点数WashInnerDim,[可选]浮点数WashQuan,[可选]浮点数IsoWashQuan,FormCollection form)
{
//删除其他功能
双倍价格=0;

如果(WashOuterDim,因为您总是将其存储在
ViewBag
上,因此您不必对代码进行太多更改

// Adds together all costs 
float Price = (float)ViewBag.SerrWasherRunPrice;

我正是这样做的,它给了我错误1一个名为“SerrWasherRunPrice”的局部变量不能在这个范围内声明,因为它会给“SerrWasherRunPrice”一个不同的含义,它已经在“父或当前”范围内用于表示其他内容