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!










share|improve this question







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.
























    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!










    share|improve this question







    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.






















      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!










      share|improve this question







      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






      share|improve this question







      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.











      share|improve this question







      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.









      share|improve this question




      share|improve this question






      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.
























          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()?






          share|improve this answer























          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          k1ngm0 is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          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
































          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()?






          share|improve this answer























          • 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















          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()?






          share|improve this answer























          • 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













          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()?






          share|improve this answer














          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()?







          share|improve this answer














          share|improve this answer



          share|improve this answer








          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


















          • 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










          k1ngm0 is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          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.















           


          draft saved


          draft discarded














          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




















































































          Popular posts from this blog

          Coverage of Google Street View

          Full-time equivalent

          Surfing