Unable to add new columns to CSV file
The following code is giving me an error on the line: modifiedRecords.Add(newRecord);
This needs to take in a CSV file, edit the data, then add additional columns of data.
61 Replies
Is the error a secret?
Error
CS1503
Argument 1: cannot convert from 'IP_Convert.MainWindow.UpdatedRecord' to 'IP_Convert.MainWindow.CsvRecord'
Sorry, forgot to post it
what do you think the error means?
That I've mixed something up somewhere
I was trying to follow someone else's advice but I'm going round in circles trying to get it working
It's really just trying to get an exisiting CSV, change some of the data in that CSV (those bits I managed), then add additional columns of data (this is where my problems started), then output the finished CSV
i can't open your code, but i'm guessing
modifiedRecords
is some kind of collection of CsvRecord
but you're trying to add a UpdatedRecord
unless UpdatedRecord
inherits CsvRecord
or defines an implicit cast to it, that can't workGitHub
IP-Convert/IP_Convert.cs at main · KonigAI/IP-Convert
Contribute to KonigAI/IP-Convert development by creating an account on GitHub.
so my guess is correct
How do i fix it?
by not trying to put the wrong type into your list
or changing the list to accept that type
OK how do I change the list to accept that type?
well, what type did you declare it to hold?
I declared all those additional entries as strings
that doesn't matter, the type itself is not compatible with the type you made your list contain
OK so whats the best way to resolve this?
by changing the type of your list to hold what you're trying to put in it
i can't really get more clear than that without writing the code for you
Have list of old type. Use select to map to new type. You now have a different list of new type. Save this to file.
the problem is
List<CsvRecord> modifiedRecords = new List<CsvRecord>();
you don't have CsvRecord
s
you have UpdatedRecord
sHow do I map a type?
the code you have is practically doing that already
the problem is simply that you are trying to put a square peg in a round hole
cannot convert from 'IP_Convert.MainWindow.UpdatedRecord' to 'IP_Convert.MainWindow.CsvRecord'
UpdatedRecord is the square peg
List<CsvRecord> is the round hole
if you want a list of UpdatedRecord
you need to make it a list of UpdatedRecord
So just use modified records instead of updatedrecords?
I feel like I've spent so long staring at this code I'm losing my mind
you can't force an instance of an
UpdatedRecord
into a CsvRecord
, they're completely different types of objects
you don't have any class called "modified record" do you?
look at this line specifically
what is modifiedRecords
and what is newRecord
?New record contains the variables in each line item that I wish to add to the list called modified records
List<CsvRecord> modifiedRecords = new List<CsvRecord>();
right, so do you see why you're getting the error?
what type is
newRecord
?Updatedrecord
is
UpdatedRecord
a CsvRecord
?It's a class
As is CSVRecord
that doesn't answer my question
it is not.
i'm trying to help you understand why you get an error for trying to add an
UpdatedRecord
to a List<CsvRecord>
I honestly think I'm just going to redo this in JS, as this is my first C# program and I am hating it
I tried doing it in C# as this small tool needs to run locally on a windows machine
This was the last stupid part I needed to do and it just breaks endlessly, man there's a reason I ditched Microsoft and I remember why
this is really not microsoft's fault
this is basic OOP
In JS or Python this would've been a lot easier
only if you refuse to understand a strongly typed programming language
In fact I have a similar python script I can probably repurpose to achieve this task
go do that i guess
i'm not gonna force you to learn
I have to do this for a job - not that coding is my primary purpose but I needed to provide a small tool to do a task, this has burned way too much time already
I just wanted help to finish it, I won't be using C# again, lesson learned
literally
that's all i wanted you to figure out
Well thank you
there's a reason we don't just solve problems for people
because you're going to run into things like this again
Look I get that, and 9 times out of 10 that's the right way. But I'm sticking to Python and JS where I am way more comfortable.
I thought it would be fun to use C# for a change but this is not for me
there are many strongly typed programming languages
besides lua and maybe some others i'm pretty sure python and JS are the 2 popular languages that aren't
In JS was more easily able to be made into desktop applications it would be great
no thanks
It's taken over everything
and with NodeJS you can do full front and backend work
dynamically typed programming languages are significantly more error prone, and JS is... JS
I don't quite get where C# fits anymore, you have Rust or C++ for really demanding stuff like games, then anything less demanding you can use JS or Python
ok
Thats a sincere question, I'm wondering where C# fits now
everywhere
it's a general purpose programming language
you can use it for web, desktop, background services, games, etc
that's like asking why anyone made a programming language other than C
I just don't see it in use much but I guess I run in different circles
i personally have no desire to use languages like JS or python, a good type system is a requirement for me
and not being slow is usually important
While I agree Python is slow, JS especially if it 'compiles' like with Svelte is pretty dam quick these days
no strong typing is a dealbreaker
if i had to do JS for any reason i'd use TS
I probably need to take actual coding classes
I'm almost entirely self taught
same
classes don't teach you to develop software
they teach you how to use a programming language
and usually using outdated versions and practices
Where's the best place to learn do you think?
pick a project and figure out how to make it using resources on the internet
And honestly I just don't have enough time to learn all the languages I would like, I find JS covers enough of my basis at this point
That's what I always do
i mean... based on the conversation earlier you didn't put much effort into understanding and fixing your problem
which is the most important thing to do
I got this far, I just got absolutely fed up with it
And then intellisense is telling me my error is somewhere else
yes, because you probably have new errors if your other code expected that list to hold CsvRecords and not UpdatedRecords