cannot convert from 'void' to 'System.Collections.Generic.List C#
up vote
0
down vote
favorite
I'm trying to add a new List for each loop in the code below to a dictionary, but I'm currently struggling with the following error:
cannot convert from 'void' to 'System.Collections.Generic.List
public class WeaponGen{
Dictionary<string, List<string>> weapons = new Dictionary <string, List<string>>();
public void WeaponGeneration(int GenerationCount)
{
Weapon weapon = new Weapon(); //this class contains basic calculation methods
weapons.Clear();
for (int i = 0; i < GenerationCount; i++)
{
string listname = "weapon" + i;
string id = Random.Range(1, 41).ToString();
List<string> _lists = new List<string>[GenerationCount];
_lists[i] = new List<string>();
weapons.Add(listname, _lists[i].Add(id)); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetName(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetRarity(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetType(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetDmg(id).ToString())); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetSpeed(id).ToString())); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetCost(id).ToString())); //this line throws an error
}
}}
Since my coding skills are definitly lacking in some aspects, I figured someone with a better grasp on the language could help me out. Every help is greatly appreciated!
c# arrays list dictionary return
New contributor
k1ngm0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
I'm trying to add a new List for each loop in the code below to a dictionary, but I'm currently struggling with the following error:
cannot convert from 'void' to 'System.Collections.Generic.List
public class WeaponGen{
Dictionary<string, List<string>> weapons = new Dictionary <string, List<string>>();
public void WeaponGeneration(int GenerationCount)
{
Weapon weapon = new Weapon(); //this class contains basic calculation methods
weapons.Clear();
for (int i = 0; i < GenerationCount; i++)
{
string listname = "weapon" + i;
string id = Random.Range(1, 41).ToString();
List<string> _lists = new List<string>[GenerationCount];
_lists[i] = new List<string>();
weapons.Add(listname, _lists[i].Add(id)); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetName(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetRarity(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetType(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetDmg(id).ToString())); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetSpeed(id).ToString())); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetCost(id).ToString())); //this line throws an error
}
}}
Since my coding skills are definitly lacking in some aspects, I figured someone with a better grasp on the language could help me out. Every help is greatly appreciated!
c# arrays list dictionary return
New contributor
k1ngm0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to add a new List for each loop in the code below to a dictionary, but I'm currently struggling with the following error:
cannot convert from 'void' to 'System.Collections.Generic.List
public class WeaponGen{
Dictionary<string, List<string>> weapons = new Dictionary <string, List<string>>();
public void WeaponGeneration(int GenerationCount)
{
Weapon weapon = new Weapon(); //this class contains basic calculation methods
weapons.Clear();
for (int i = 0; i < GenerationCount; i++)
{
string listname = "weapon" + i;
string id = Random.Range(1, 41).ToString();
List<string> _lists = new List<string>[GenerationCount];
_lists[i] = new List<string>();
weapons.Add(listname, _lists[i].Add(id)); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetName(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetRarity(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetType(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetDmg(id).ToString())); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetSpeed(id).ToString())); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetCost(id).ToString())); //this line throws an error
}
}}
Since my coding skills are definitly lacking in some aspects, I figured someone with a better grasp on the language could help me out. Every help is greatly appreciated!
c# arrays list dictionary return
New contributor
k1ngm0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I'm trying to add a new List for each loop in the code below to a dictionary, but I'm currently struggling with the following error:
cannot convert from 'void' to 'System.Collections.Generic.List
public class WeaponGen{
Dictionary<string, List<string>> weapons = new Dictionary <string, List<string>>();
public void WeaponGeneration(int GenerationCount)
{
Weapon weapon = new Weapon(); //this class contains basic calculation methods
weapons.Clear();
for (int i = 0; i < GenerationCount; i++)
{
string listname = "weapon" + i;
string id = Random.Range(1, 41).ToString();
List<string> _lists = new List<string>[GenerationCount];
_lists[i] = new List<string>();
weapons.Add(listname, _lists[i].Add(id)); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetName(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetRarity(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetType(id))); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetDmg(id).ToString())); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetSpeed(id).ToString())); //this line throws an error
weapons.Add(listname, _lists[i].Add(weapon.GetCost(id).ToString())); //this line throws an error
}
}}
Since my coding skills are definitly lacking in some aspects, I figured someone with a better grasp on the language could help me out. Every help is greatly appreciated!
c# arrays list dictionary return
c# arrays list dictionary return
New contributor
k1ngm0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
k1ngm0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
k1ngm0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 days ago
k1ngm0
62
62
New contributor
k1ngm0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
k1ngm0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
k1ngm0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Welcome to SO!
List add method does not return any value: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.add?view=netframework-4.7.2.
So, if I understood your idea correctly, you need to fill the list with needed values and add it itself to the dictionary, like this:
for (int i = 0; i < GenerationCount; i++)
{
string listname = "weapon" + i;
string id = Random.Range(1, 41).ToString();
List<string> _lists = new List<string>[GenerationCount];
_lists[i] = new List<string>();
_lists[i].Add(id);
_lists[i].Add(weapon.GetName(id));
_lists[i].Add(weapon.GetRarity(id));
_lists[i].Add(weapon.GetType(id));
_lists[i].Add(weapon.GetDmg(id).ToString());
_lists[i].Add(weapon.GetSpeed(id).ToString());
_lists[i].Add(weapon.GetCost(id).ToString());
weapons.Add(listname, _lists[i]);
}
P.S. What is it Random.Range? Is it some extention method? In any case, it seems to be dangerous to generate id's based on random value in such small interval. Why not simple use i.ToString()?
Thank you, this is a very quick and easy solution to my problem :) I'd upvote your answer if I could!
– k1ngm0
2 days ago
This code is for a game I'm working on and Random.Range is inherited from the UnityEngine namespace. I'm getting my values from a .csv file which has a row for id's. I use this method to randomly pick an ID from that list (the interval is basically the upper and lower bound of that .csv) and generate the relevant weapon data for that ID. So these id's are actually like keys for me :D
– k1ngm0
2 days ago
Ok, this is the nice explanation)
– Miamy
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Welcome to SO!
List add method does not return any value: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.add?view=netframework-4.7.2.
So, if I understood your idea correctly, you need to fill the list with needed values and add it itself to the dictionary, like this:
for (int i = 0; i < GenerationCount; i++)
{
string listname = "weapon" + i;
string id = Random.Range(1, 41).ToString();
List<string> _lists = new List<string>[GenerationCount];
_lists[i] = new List<string>();
_lists[i].Add(id);
_lists[i].Add(weapon.GetName(id));
_lists[i].Add(weapon.GetRarity(id));
_lists[i].Add(weapon.GetType(id));
_lists[i].Add(weapon.GetDmg(id).ToString());
_lists[i].Add(weapon.GetSpeed(id).ToString());
_lists[i].Add(weapon.GetCost(id).ToString());
weapons.Add(listname, _lists[i]);
}
P.S. What is it Random.Range? Is it some extention method? In any case, it seems to be dangerous to generate id's based on random value in such small interval. Why not simple use i.ToString()?
Thank you, this is a very quick and easy solution to my problem :) I'd upvote your answer if I could!
– k1ngm0
2 days ago
This code is for a game I'm working on and Random.Range is inherited from the UnityEngine namespace. I'm getting my values from a .csv file which has a row for id's. I use this method to randomly pick an ID from that list (the interval is basically the upper and lower bound of that .csv) and generate the relevant weapon data for that ID. So these id's are actually like keys for me :D
– k1ngm0
2 days ago
Ok, this is the nice explanation)
– Miamy
2 days ago
add a comment |
up vote
1
down vote
accepted
Welcome to SO!
List add method does not return any value: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.add?view=netframework-4.7.2.
So, if I understood your idea correctly, you need to fill the list with needed values and add it itself to the dictionary, like this:
for (int i = 0; i < GenerationCount; i++)
{
string listname = "weapon" + i;
string id = Random.Range(1, 41).ToString();
List<string> _lists = new List<string>[GenerationCount];
_lists[i] = new List<string>();
_lists[i].Add(id);
_lists[i].Add(weapon.GetName(id));
_lists[i].Add(weapon.GetRarity(id));
_lists[i].Add(weapon.GetType(id));
_lists[i].Add(weapon.GetDmg(id).ToString());
_lists[i].Add(weapon.GetSpeed(id).ToString());
_lists[i].Add(weapon.GetCost(id).ToString());
weapons.Add(listname, _lists[i]);
}
P.S. What is it Random.Range? Is it some extention method? In any case, it seems to be dangerous to generate id's based on random value in such small interval. Why not simple use i.ToString()?
Thank you, this is a very quick and easy solution to my problem :) I'd upvote your answer if I could!
– k1ngm0
2 days ago
This code is for a game I'm working on and Random.Range is inherited from the UnityEngine namespace. I'm getting my values from a .csv file which has a row for id's. I use this method to randomly pick an ID from that list (the interval is basically the upper and lower bound of that .csv) and generate the relevant weapon data for that ID. So these id's are actually like keys for me :D
– k1ngm0
2 days ago
Ok, this is the nice explanation)
– Miamy
2 days ago
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Welcome to SO!
List add method does not return any value: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.add?view=netframework-4.7.2.
So, if I understood your idea correctly, you need to fill the list with needed values and add it itself to the dictionary, like this:
for (int i = 0; i < GenerationCount; i++)
{
string listname = "weapon" + i;
string id = Random.Range(1, 41).ToString();
List<string> _lists = new List<string>[GenerationCount];
_lists[i] = new List<string>();
_lists[i].Add(id);
_lists[i].Add(weapon.GetName(id));
_lists[i].Add(weapon.GetRarity(id));
_lists[i].Add(weapon.GetType(id));
_lists[i].Add(weapon.GetDmg(id).ToString());
_lists[i].Add(weapon.GetSpeed(id).ToString());
_lists[i].Add(weapon.GetCost(id).ToString());
weapons.Add(listname, _lists[i]);
}
P.S. What is it Random.Range? Is it some extention method? In any case, it seems to be dangerous to generate id's based on random value in such small interval. Why not simple use i.ToString()?
Welcome to SO!
List add method does not return any value: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.add?view=netframework-4.7.2.
So, if I understood your idea correctly, you need to fill the list with needed values and add it itself to the dictionary, like this:
for (int i = 0; i < GenerationCount; i++)
{
string listname = "weapon" + i;
string id = Random.Range(1, 41).ToString();
List<string> _lists = new List<string>[GenerationCount];
_lists[i] = new List<string>();
_lists[i].Add(id);
_lists[i].Add(weapon.GetName(id));
_lists[i].Add(weapon.GetRarity(id));
_lists[i].Add(weapon.GetType(id));
_lists[i].Add(weapon.GetDmg(id).ToString());
_lists[i].Add(weapon.GetSpeed(id).ToString());
_lists[i].Add(weapon.GetCost(id).ToString());
weapons.Add(listname, _lists[i]);
}
P.S. What is it Random.Range? Is it some extention method? In any case, it seems to be dangerous to generate id's based on random value in such small interval. Why not simple use i.ToString()?
edited 2 days ago
answered 2 days ago
Miamy
600310
600310
Thank you, this is a very quick and easy solution to my problem :) I'd upvote your answer if I could!
– k1ngm0
2 days ago
This code is for a game I'm working on and Random.Range is inherited from the UnityEngine namespace. I'm getting my values from a .csv file which has a row for id's. I use this method to randomly pick an ID from that list (the interval is basically the upper and lower bound of that .csv) and generate the relevant weapon data for that ID. So these id's are actually like keys for me :D
– k1ngm0
2 days ago
Ok, this is the nice explanation)
– Miamy
2 days ago
add a comment |
Thank you, this is a very quick and easy solution to my problem :) I'd upvote your answer if I could!
– k1ngm0
2 days ago
This code is for a game I'm working on and Random.Range is inherited from the UnityEngine namespace. I'm getting my values from a .csv file which has a row for id's. I use this method to randomly pick an ID from that list (the interval is basically the upper and lower bound of that .csv) and generate the relevant weapon data for that ID. So these id's are actually like keys for me :D
– k1ngm0
2 days ago
Ok, this is the nice explanation)
– Miamy
2 days ago
Thank you, this is a very quick and easy solution to my problem :) I'd upvote your answer if I could!
– k1ngm0
2 days ago
Thank you, this is a very quick and easy solution to my problem :) I'd upvote your answer if I could!
– k1ngm0
2 days ago
This code is for a game I'm working on and Random.Range is inherited from the UnityEngine namespace. I'm getting my values from a .csv file which has a row for id's. I use this method to randomly pick an ID from that list (the interval is basically the upper and lower bound of that .csv) and generate the relevant weapon data for that ID. So these id's are actually like keys for me :D
– k1ngm0
2 days ago
This code is for a game I'm working on and Random.Range is inherited from the UnityEngine namespace. I'm getting my values from a .csv file which has a row for id's. I use this method to randomly pick an ID from that list (the interval is basically the upper and lower bound of that .csv) and generate the relevant weapon data for that ID. So these id's are actually like keys for me :D
– k1ngm0
2 days ago
Ok, this is the nice explanation)
– Miamy
2 days ago
Ok, this is the nice explanation)
– Miamy
2 days ago
add a comment |
k1ngm0 is a new contributor. Be nice, and check out our Code of Conduct.
k1ngm0 is a new contributor. Be nice, and check out our Code of Conduct.
k1ngm0 is a new contributor. Be nice, and check out our Code of Conduct.
k1ngm0 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238365%2fcannot-convert-from-void-to-system-collections-generic-liststring-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password