I've recently begun to learn C#. As you can see from this code snippet:
Scanner file = new Scanner(new File("hashValues.txt"));
String miningDay = "";
String currency = "";
double netPayOut = 0.0;
String i = "";
String walletID = "";
Array hashValues;
while(file.hasNext())
{
miningDay = file.next();
currency = file.next();
netPayOut = file.nextDouble();
i = file.next();
walletID = file.next();
}
Java has a class called Scanner which allows you to open a file through the file class. The Scanner class has functions to read individual strings, as well as int and double data types. Does C# have something similar to this? I tried to do something like this, but it doesn't really work.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.IO;
namespace Mod3_Lab1
{
class Program
{
static void Main(string[] args)
{
StreamReader addressBook = null;
String Name = "";
String Address = "";
try
{
addressBook = new StreamReader("address_book.txt");
while(!addressBook.EndOfStream)
{
Name = addressBook.ReadLine();
Address = addressBook.ReadLine();
}
addressBook.Close();
Console.WriteLine("Name: " + Name);
Console.WriteLine("Address: " + Address);
}
catch(FileNotFoundException)
{
}
}
}
}
Here is the output: