Skip to content

Instantly share code, notes, and snippets.

@richlander
Last active February 2, 2019 01:11
Show Gist options
  • Save richlander/7213b5dcaf011ad0cbe3d2582697b228 to your computer and use it in GitHub Desktop.
Save richlander/7213b5dcaf011ad0cbe3d2582697b228 to your computer and use it in GitHub Desktop.
C# 8 Using Declaration
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