Last active
February 2, 2019 01:11
-
-
Save richlander/7213b5dcaf011ad0cbe3d2582697b228 to your computer and use it in GitHub Desktop.
C# 8 Using Declaration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
using static System.Console; | |
using System.IO; | |
namespace usingapp | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
var filename = "Program.cs"; | |
var line = string.Empty; | |
var magicString = "magicString"; | |
var file = new FileInfo(filename); | |
using var reader = file.OpenText(); | |
while ((line = reader.ReadLine())!= null) | |
{ | |
if (line.Contains(magicString)) | |
{ | |
WriteLine("Found string"); | |
return; | |
} | |
} | |
WriteLine("String not found"); | |
} // reader disposed here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment