Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have data(list of horse names) that I want to create a program for. The program I want to create will save the horse names to a csv file but then I want to be able to limit the number of horse names that are transferred to the file each time, there's 100 names, I want to be able to at times pick ten, then another time pick fifteen? I'm trying to do this via a console application and want to input the horses names at the time of coding, instead of via the console, I just want to randomly generate the names into a csv file. Its for a show.

Can anyone help me do this?
Posted

1 solution

If you just want the horse names, then possibly CSV is a little overkill - a simple list with one name per line is easy to read and write and needs no special processing:
Assuming you have your names in an array (just the ten you are interested in)
Write:
C#
File.WriteAllLines(path, horses);

Read:
C#
string[] horses = File.ReadAllLines(path);
If you have to use CSV, then see here: Reading and Writing CSV Files in C#[^] for a quick and simple version.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900