The Console.SetIn() method is used to set the In property of the specified StreamReader object i.e. it redirects the standard input from the console to the input file. Since the console is set with this StreamReader object, the ReadLine() method can be called to read the contents of the file, line by line.
Syntax: public static void SetIn (System.IO.StreamReader newIn);
newIn: It is a stream which is the new standard input.
- ArgumentNullException: If the newIn is null.
- SecurityException: If the caller does not have the required permission.
Example: In this example, the SetIn() method is used to set the StreamReader object to the console, and the file’s content will be read, stored and printed.
Text File Used:
- Difference between Method Overriding and Method Hiding in C#
- Stack.Contains() Method in C#
- DateTimeOffset.Add() Method in C#
- DateTime.Add() Method in C#
- C# | Uri.IsWellFormedOriginalString() Method
- C# | Uri.ToString() Method
- C# | PadLeft() Method
- C# | Join() Method | Set - 1
- jQuery | before() Method
- C# | IndexOfAny() Method
- C# | Trim() Method
- C# | StartsWith() Method
- C# | Math.Pow() Method
- jQuery | off() Method
- Stack.Pop() Method in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.