第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如果 (Integer Console.Readline "" or null) 不起作用

如果 (Integer Console.Readline "" or null) 不起作用

C#
狐的傳說 2021-07-28 21:05:05
在搜索和搜索(你知道它是怎么回事)之后,我無法弄清楚為什么這段代碼不起作用。我只是想讓它像這樣工作if (Nummer == "") {    Console.WriteLine("0");}就是這樣,它不起作用。我已經(jīng)找了一個(gè)半小時(shí)了。不明白為什么有一個(gè)簡單的基本解釋。我只找到了如何用字符串或其他東西修復(fù)它,然后我嘗試轉(zhuǎn)換它,但它仍然不起作用。有人能幫助我嗎?感謝您對我有限的知識的耐心。謝謝你的時(shí)間static void Main(string[] args){    bool herhaal = true;    do    {                        Console.Write("Geef een getal : ");        int Nummer = Convert.ToInt16(Console.ReadLine());                   if (Console.ReadLine() == "" && Console.ReadLine() == null)        {            Console.WriteLine("0");        }        double kw = Math.Pow(Nummer, 2);        Console.WriteLine("Kwadraat van {0} is: {1}", Nummer, kw + Environment.NewLine);    } while (herhaal);}
查看完整描述

3 回答

?
弒天下

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊

static void Main(string[] args)

{

    int Nummer;

    bool herhaal = true;

    do

    {                

        Console.Write("Geef een getal : ");          

        //only read from the Console ONCE per loop iteration, and always read to a string first

        string input = Console.ReadLine(); 


        //TryParse better than Convert for converting strings to integers

        if (!int.TryParse(input, out Nummer))        

        {

            Console.WriteLine("0");

        }

        else  //only do the second part if the conversion worked

        {

            double kw = Math.Pow(Nummer, 2);

            Console.WriteLine("Kwadraat van {0} is: {1}\n", Nummer, kw);

        }


    } while (herhaal);

}

要從 WinForms 應(yīng)用程序執(zhí)行此操作,如評論中所嘗試:


private void button1_Click(object sender, EventArgs e)

{

    double aantalgroep;

    if (!double.TryParse(textBox1.Text, out aantalgroep))        

    {

        textBox1.Text = "0";

    }

    else 

    {

        double kw = Math.Pow(aantalgroep, 2);

        textBox1.Text = String.Format("Kwadraat van {0} is: {1}", aantalgroep, kw);

    }

}


查看完整回答
反對 回復(fù) 2021-07-31
?
翻閱古今

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊

根據(jù) C# 文檔,Console.ReadLine執(zhí)行以下操作

從標(biāo)準(zhǔn)輸入流中讀取下一行字符。

這意味著每次調(diào)用時(shí)Console.ReadLine,都會(huì)從控制臺讀取一個(gè)新行。從我在你的代碼中看到的,這不是你想要的行為。要解決您的問題,您應(yīng)該將 的結(jié)果存儲Console.ReadLine在一個(gè)變量中并使用該變量而不是 ReadLine 方法。


查看完整回答
反對 回復(fù) 2021-07-31
  • 3 回答
  • 0 關(guān)注
  • 216 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號