Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
List<Animals> alumnos = new List<Animals>();


 class Animals{ 
int Idanimals  { get; set; }
int Type { get; set; }
}


0 = cat
1 = dog
2 = bird

animals[2] = "Dog";


Then upload them to a DVgrid
Help me!!!!

What I have tried:

animals[2] = "Dog";


But I get error
CS0029 C # Can not implicitly convert type 'string' to 'Project.Animals'
Posted
Updated 24-Aug-17 5:58am
Comments
BillWoodruff 24-Aug-17 14:52pm    
Your definition of 'Animals contains two integer Properties: what makes you think you can use a string ?

1 solution

C#
animals[2] = "Dog";

But (according to the compiler) you defined animals as a collection of Animals, not a collection of strings. So you need to create a new Animal and assign that to your list, like:
C#
Animals newDog = new Animals(1, "Dog");
animals[2] = newDog;
 
Share this answer
 
Comments
BillWoodruff 24-Aug-17 14:56pm    
The OP's code won't take a string in the ctor for 'Animals; either some information is missing ... or ?
Richard MacCutchan 24-Aug-17 15:17pm    
Yes, I know; I was just trying to show the difference between string and object, since the Animals class is a bit pointless.
Richard MacCutchan 24-Aug-17 15:25pm    
Yes, I am aware of that.
BillWoodruff 25-Aug-17 10:08am    
With this type of confused question, I think it best to wait for some clarification from the OP.
Richard MacCutchan 25-Aug-17 10:12am    
I usually find it's best not to hold your breath while waiting for such clarification. :)

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