A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the File Input Output in Beef page! Here, you'll find the source code for this program as well as a description of how the program works.
using System;
using System.IO;
namespace FileInputOutput;
class Program
{
public static Result<void> WriteFile(StringView filename)
{
StreamWriter fs = scope .();
Try!(fs.Create(filename));
fs.WriteLine("Hello from Beef!");
fs.WriteLine("This is line 1");
fs.WriteLine("This is line 2");
fs.WriteLine("Goodbye!");
return .Ok;
}
public static Result<void> ReadFile(StringView filename)
{
StreamReader fs = scope .();
Try!(fs.Open(filename));
String line = scope .();
while (fs.ReadLine(line) case .Ok)
{
Console.WriteLine(line);
line.Clear();
}
return .Ok;
}
public static int Main(String[] args)
{
String filename = "output.txt";
if (WriteFile(filename) case .Err)
{
Console.WriteLine($"Could not write {filename}");
}
if (ReadFile(filename) case .Err)
{
Console.WriteLine($"Could not read {filename}");
}
return 0;
}
}
File Input Output in Beef was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.