>  기사  >  백엔드 개발  >  C#의 Console.Read() 메서드에 대한 자세한 설명

C#의 Console.Read() 메서드에 대한 자세한 설명

藏色散人
藏色散人원래의
2019-03-25 13:21:328991검색

Console.Read() 메서드는 표준 입력 스트림에서 다음 문자를 읽는 데 사용됩니다. 이 방법은 기본적으로 사용자가 일부 입력 문자를 입력할 때 반환되는 것을 방지합니다. 사용자가 ENTER를 누르면 종료됩니다.

C#의 Console.Read() 메서드에 대한 자세한 설명

구문: ​​

public static int Read();

반환 값: 입력 스트림의 다음 문자를 반환하거나, 현재 읽을 문자가 없는 경우 음수(-1)를 반환합니다.

Exception: 이 메서드는 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); 
    } 
} 
}

출력:

C#의 Console.Read() 메서드에 대한 자세한 설명

예제 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)); 
    } 
} 
}

출력:

C#의 Console.Read() 메서드에 대한 자세한 설명

관련 추천 : 《 C Tutorial

이 글은 C#의 Console.Read() 메소드에 대한 자세한 설명입니다. 도움이 필요한 친구들에게 도움이 되길 바랍니다!

위 내용은 C#의 Console.Read() 메서드에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.