您好,登錄后才能下訂單哦!
這篇文章主要介紹了C#中Console.Read()方法的案例分析,具有一定借鑒價值,需要的朋友可以參考下。希望大家閱讀完這篇文章后大有收獲。下面讓小編帶著大家一起了解一下。
Console.Read()方法用于從標(biāo)準(zhǔn)輸入流中讀取下一個字符。當(dāng)用戶鍵入一些輸入字符時,此方法基本上阻止其返回。一旦用戶按ENTER鍵,它就會終止。
語法:
public static int Read();
返回值:返回輸入流中的下一個字符,如果當(dāng)前沒有要讀取的字符,則返回負(fù)數(shù)(-1)。
例外:如果發(fā)生I / O錯誤,此方法將給出IOException。
以下程序說明了上述方法的使用:
示例1:
// C# program to illustrate the use // of Console.Read Method using System; namespace GFG { class Program { static void Main(string[] args) { int x; Console.WriteLine("Enter your Character to get Decimal number"); // using the method x = Console.Read(); Console.WriteLine(x); } } }
輸出:
示例2:
// C# program to illustrate the use // of Console.Read Method using System; namespace GFG { class Program { static void Main(string[] args) { // Write to console window. int x; Console.WriteLine("Enter your Character to get Decimal number"); x = Console.Read(); Console.WriteLine(x); // Converting the decimal into character. Console.WriteLine(Convert.ToChar(x)); } } }
輸出:
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享C#中Console.Read()方法的案例分析內(nèi)容對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,遇到問題就找億速云,詳細(xì)的解決方法等著你來學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。