How can I perform calculation operations with data obtained from a .txt file in C # implementing the StreamReader class?

0

How can I perform calculation operations with data obtained from a .txt file in C # implementing class StreamReader ?

The data is in the form of a table of employees with their respective salaries and hours worked in a text file.

What I need is that when executing, the StreamReader in the program shows that table, but with the calculation made through the data previously entered in the text file.

    
asked by Ramon 19.07.2016 в 17:21
source

1 answer

1

In principle with class StreamReader you can not perform any calculation calculation because with this you would only read the file.

But if you could dump the data from the file to a class and in this if you implement logic to calculate what you need

I would recommend evaluates

filehelpers

with this you could map the file to a class that you define in a simple way, then the data is parsed and you could use it in the calculations

You can define a class as being

[DelimitedRecord("|")]
public class Orders
{
    public int OrderID;

    public string CustomerID;

    [FieldConverter(ConverterKind.Date, "ddMMyyyy")]
    public DateTime OrderDate;

    [FieldConverter(ConverterKind.Decimal, ".")] // The decimal separator is .
    public decimal Freight;
}

and pause it using

var engine = new FileHelperEngine<Orders>();
var records = engine.ReadFile("Input.txt");

foreach (var record in records)
{
    Console.WriteLine(record.CustomerID);
    Console.WriteLine(record.OrderDate.ToString("dd/MM/yyyy"));
    Console.WriteLine(record.Freight);
}

As you will see in the example, use the properties to recover the data and perform operations with these

    
answered by 19.07.2016 в 17:38