Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Array.ToList() Returning Error

$
0
0
Hello! I have been encountering a problem while converting my Array into a List using the .ToList() method (I'm a little new to Object Oriented Programming and Networking so I apologize if my code is messy). I have a class named "Player" and I have a list named "players" which is a list of type Player (List). I need to send this list to all clients connected to the server, and an RPC will not let me send lists. I looked up how to do it, and I was told to convert my list to an array (using .ToArray()) and then converting it back to a list on the other end (using .ToList()). However, I receive the following error: error CS0411: The type arguments for method `System.Linq.Enumerable.ToList(this System.Collections.Generic.IEnumerable)' cannot be inferred from the usage. Try specifying the type arguments explicitly This is my code: For sending the RPC and converting the array to a list: networkView.RPC ("updateClients", RPCMode.Others, players.ToArray ()); For receiving and setting the players list on the clients end: [RPC] void updateClients(Array serverPlayers){ players = serverPlayers.ToList (); } Also: using System.Linq; is included at the top of the script. I have looked up this error, but have found nothing that could help me. Does anyone know what I am doing wrong? Would it make more sense to just switch everything to an Array? Thank you!

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>