18 Replies
List<T> implements IList<T>
you can just cast it, or pass it to a method that expects IList<T>, no conversion needed
but i get an error when i try to assign my a List<T> to an IList<T>, how do i get around this issue
show the $code and the error
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/here is the codesnippit
the error is:
Error CS0200 Property or indexer 'ChatCompletionsOptions.Messages' cannot be assigned to -- it is read only
that's not a List vs IList issue
that's the property not having a setter
presumably you're meant to call Add or AddRange on Messages instead of reassigning it
I can't call AddRange as it does not exits, and i cant ude Add as i need to a whole lot of old things to it
Don't hesitate to read the error message. It literally says, that what you are trying to set is readonly - you cannot assign to it
Addrange is basically calling add in a loop
Yes, but this works
Okay, then I will make my own, but why can i assign a new list and not a variable
Are you sure you need to assign to the messages property
Click on the messages property and press F12, show a screenshot of what appears
this?
Yes. This clearly shows that you do not set messages via the property, as it only has a
get
This explains the read-only error
You supply the messages via the constructor
Or, I would assume you store your ChatCompletionOptions
in a separate variable and access its Messages property to directly add your messages there
ahh, thats clever, no idea why i didn't think of that
And then provide the options to your GetChatCompletionOptions method
yes, that makes so much more sense, thank you so much
Welcome, try it out
It might happen that the mesaages are null
But hopefully that is not the case
If it is null, then you can provide the messages via the constructor
As seen in the screenshot you've shared
This
Oh no, it is internal
Then maybe there is a different constructor available
okay, great, thank you so much again, it seems that it works to just save the GetChatCompletionOptions
Consider closing this thread using /close if you have no further questions