C
C#2y ago
Sam DZ

✅ write multiple Lists to file

I want to write several items from lists that have same index to text file, what is the easiest way
49 Replies
TheRanger
TheRanger2y ago
what do u mean by same index to text file
boom
boom2y ago
@It's_Sam
List<string> Data1 = new List<string>();
List<string> Data2 = new List<string>();

public void WriteLists(List<string>[] lists)
{
int index = 7; // some random index
foreach(List<string> data in lists)
{
if(data.Count >= index)
{
// write data to file
data[index];
}
}
}
List<string> Data1 = new List<string>();
List<string> Data2 = new List<string>();

public void WriteLists(List<string>[] lists)
{
int index = 7; // some random index
foreach(List<string> data in lists)
{
if(data.Count >= index)
{
// write data to file
data[index];
}
}
}
is this what you're wanting?
Sam DZ
Sam DZOP2y ago
@TheRanger The value inside the List have same index
Angius
Angius2y ago
Why does the index matter...?
boom
boom2y ago
do both lists have equal length in elements in relation to the specific index??
Angius
Angius2y ago
Write all lines from one list Write all lines from the second list Done
Sam DZ
Sam DZOP2y ago
@driveby no they don't have same length
boom
boom2y ago
and you're wanting index N from both lists written to a file?
Sam DZ
Sam DZOP2y ago
It's a project for college And I'm storing infos in lists
boom
boom2y ago
you want all those in 1 file? just do what he said
Angius
Angius2y ago
Ah I see the issue... I think
Sam DZ
Sam DZOP2y ago
Yes in 1 file
Angius
Angius2y ago
Instead of having a list of objects, you have multiple lists storing properties
TheRanger
TheRanger2y ago
why not make a class called Ship with properties Name, Price , etc....
Angius
Angius2y ago
Instead of a list of people, each of which has a name and age, you have a list of names and list of ages That's not the way to go about it whatsoever
boom
boom2y ago
ohhhhhhhh i see what he needs
List<dynamic> Data1 = new List<dynamic>();
List<dynamic> Data2 = new List<dynamic>();

// using dynamic just bc i dont know datatypes
public void WriteLists(List<dynamic>[] lists)
{
int index = 0;
foreach(List<dynamic> data in lists)
{
WriteText(data[index]);
}
WriteText("\r\n");
}
List<dynamic> Data1 = new List<dynamic>();
List<dynamic> Data2 = new List<dynamic>();

// using dynamic just bc i dont know datatypes
public void WriteLists(List<dynamic>[] lists)
{
int index = 0;
foreach(List<dynamic> data in lists)
{
WriteText(data[index]);
}
WriteText("\r\n");
}
like this? i havent tested but something similiar?
Angius
Angius2y ago
dynamic
TheRanger
TheRanger2y ago
dont ever use dynamic, ever
Angius
Angius2y ago
Jesus
boom
boom2y ago
u can see the comment
Angius
Angius2y ago
You made it worse
boom
boom2y ago
stop being weird
TheRanger
TheRanger2y ago
yes i can see the comment
Angius
Angius2y ago
Using dynamic is what's weird
TheRanger
TheRanger2y ago
ur point?
Angius
Angius2y ago
Just make up some random Order class or whatever
Sam DZ
Sam DZOP2y ago
I'm wondering what would be right A little Joyner asking lol
Angius
Angius2y ago
Using dynamic even as an example tells people it's fine to use it It's not fine to use it A class that describes your objects
boom
boom2y ago
well, at this rate, they're just criticizing stupid shit, hopefully they'll help you pce
TheRanger
TheRanger2y ago
something like
public class Ship
{
public string Name {get;set;}
public decimal Price {get;set;}
public int Quantity {get;set;}

public string Address {get;set;}
public string ShippingType {get;set;}
public string PayType {get;set;}
}
public class Ship
{
public string Name {get;set;}
public decimal Price {get;set;}
public int Quantity {get;set;}

public string Address {get;set;}
public string ShippingType {get;set;}
public string PayType {get;set;}
}
and in ur class Shipping
class Shipping
{
public static List<Ship> Ships = new List<Ship>();
}
class Shipping
{
public static List<Ship> Ships = new List<Ship>();
}
Sam DZ
Sam DZOP2y ago
This the final class where show to user what he put in the cart You can say it's just using Console.writeline after showing it in Console app I want to save it in file to desktop
Angius
Angius2y ago
Structure your data properly and writing it to a file won't be an issue
boom
boom2y ago
lol how are you an associate with that kinda attitude 😂
Angius
Angius2y ago
?
Sam DZ
Sam DZOP2y ago
@TheRanger I will shook you I tried a lot to know how to use properties and Didn't get it 💔
Angius
Angius2y ago
"How do I eat soup with a fork"? "You shouldn't, use a spoon instead" "lol how are you an associate with that kinda attitude 😂" Whatever, issue seems to be solved That's what matters
Sam DZ
Sam DZOP2y ago
Can u guys recommended to me a video or doc for properties plz 🥹😂
TheRanger
TheRanger2y ago
well id recommend you this tutorial $helloworld
TheRanger
TheRanger2y ago
if you want to only see a video for properties specifically, it should be somewhere in the videos link but in general, you should learn all of the fundamentals of C#
Sam DZ
Sam DZOP2y ago
@TheRanger I write about 700 line For this project Bot oop it's kinda new to me so iam facing some issues
TheRanger
TheRanger2y ago
take your time
Angius
Angius2y ago
OOP is the base of C# It's honestly impressive you managed to write something this big without OOP, only got stuck on saving data to a file
Sam DZ
Sam DZOP2y ago
Nooo It have 9 classes It's fully oop @Angius
Angius
Angius2y ago
Ah, gotcha I thought it's all written with parallel lists of properties lol
Sam DZ
Sam DZOP2y ago
But this is the first time i made an oop console app @Angius Can i talk to u in dm to ask for several things?
Angius
Angius2y ago
Not really, no Feel free to ask here
TheRanger
TheRanger2y ago
ull get help from more than a single person in here
Sam DZ
Sam DZOP2y ago
Ok thank you all very much for giving me a hand /close
Want results from more Discord servers?
Add your server