Mats Larsson

Mats Larsson

  • NA
  • 25
  • 1.1k

write textfie from code

Nov 27 2022 9:05 AM

have creat this cod. 

but i want to write it to a text file. have try witch File.WriteAllLinesAsync and streamwriter. but I want to salesmen.Count() to a textfile

using System.IO; 
using System.Text;
using System;
using System.Security.Cryptography.X509Certificates;

namespace project
{

 

internal class salesman // class for the salesman
{

public string name;
public string person;
public string location;
public int count;

public salesman(string name, string person, string location, int number) // calls the variables
{
this.name = name; // this. = reference to the class
this.person = person;
this.location = location; // location
this.number = number;
}

}
internal class Program
{
static void Main(string[] args)
{

Console.WriteLine(" number of sales layers to be registered");
int snus = int.Parse(Console.ReadLine() ?? "0"); // enter how many sellers are to be registered

List<salesman> salesman = new List<salesman>(); // list for the class

for (int j = 0; j < snus; j++)
{

Console.WriteLine();
Console.WriteLine(" your name ");
var fornman = Console.ReadLine() ?? "0";
Console.WriteLine(" social security number ");
var number = Console.ReadLine() ?? "0";
Console.WriteLine(" enter palts/district ");
var dist = Console.ReadLine() ?? "0";
Console.WriteLine(" enter number ");
var items = int.Parse(Console.ReadLine() ?? "0");

Console.WriteLine();
var sa = new salesman(firstman, number, dist, items);

sälajre.Add(sa); //calls the method
}

var level1 = selajre.Where(n => n.number < 50); // level1
method seller(1, level1); // calls the method

var level2 = selajre.Where(n => n.count >= 50 && n.count < 100); // level2
method seller(2, level2);
var level3 = selajre.Where(n => n.count >= 100 && n.count < 200);// level3
method seller(3, level3);

var level4 = selajre.Where(n => n.number > 200); // level4
method seller(4, level4);
Console.ReadLine();

}
static async void method salesman(int level, IEnumerable<salesman> salesmen) // method salesman
{
if (!salesmen.Any())
{
return;
}


Console.WriteLine("-------------------");
// Console.WriteLine(salesmen.Count() + " salesman has reached level " + level);


foreach (var rape in salesmen.OrderBy(n => n.number)) // foreach is used to repeat the narrowing
{


Console.WriteLine("Name: " + rape.name); //  displays seller names
Console.WriteLine("Personal ID: " + rape.person); //
Console.WriteLine("District/Location: " + rape.location); // display location
Console.WriteLine("Number sold " + rape.number); // shows how many items sold
Console.WriteLine("Seller has reached level " + level); // determines what level the seller has reached
Console.WriteLine("-----------------------------");


Console.WriteLine("-----------------------------");


// await File.WriteAllLinesAsync(@"C:\Users\lol\OneDrive\Documents\business account view\tabort\tt", rape.name);


}

//File.WriteAllLines(path, salesmen.Count() + " salesmen has reached level " + level, Encoding.UTF8);
Console.WriteLine(salesmen.Count() + " salesman has reached level " + level); // prints the level at which most sellers have sold


File.WriteAllLinesAsync( "file that i save my textfile" + level);


Answers (1)