j'ai un problĆØme avec mon code | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

j'ai un problĆØme avec mon code

je crƩer un RPG seulement avec du C# j'ai crƩer un objet (Player) et quand je veux lui associer un race avec GetRace(); ca me fait un erreur voici mon code : using System; public class Program { public class Player { private string name; public static string race; private static int force; private static int charisme; private static int constitution; private static int agiletƩe; public static void GetRace() { Console.WriteLine("quelle race ets tu entre : orc , humain , elfe ou nain"); Console.WriteLine("orc : plus de force"); Console.WriteLine("humain : plus de charisme"); Console.WriteLine("elfe : plus d'agiletƩ"); Console.WriteLine("nain : plus de constittion(PV)"); race = Console.ReadLine(); } } public static void Main() { Player C1 = new Player(); C1.GetRace(); } } voici mon erreur : Member 'Program.Player.GetRace()' cannot be accessed with an instance reference; qualify it with a type name instead

3rd Aug 2022, 9:24 PM
Raphaƫl
Raphaƫl - avatar
2 Respostas
+ 1
dƩsolƩ je vien de remarquƩ la faue d'ortographe au nain
3rd Aug 2022, 9:26 PM
Raphaƫl
Raphaƫl - avatar
0
GetRace() est une mĆ©thode static. Donc utilise Player.GetRace() ou enlĆØve les clefs statics. Il vaut mieux enlever les static car un Ć©lĆ©ment static d'une classe est unique, si tu as plusieurs player tu ne pourra pas avoir des attributs diffĆ©rents par players.
4th Aug 2022, 5:34 AM
Roland
Roland - avatar