0

How do i add a parameter to a label?

Hi everyone, I am trying to create a simple nation simulator game. I created a "Nations" class with military, diplomatic and industry properties. I instantiated an object called "Italy" from the nations class, and i assigned a value to the properties i created before. Now i would like to change the text of a label to the military score of the object "Italy" LblMil_Score.Text=Italy.mil; The problem is that this doesn't work. Can someone tell me how to change the value of the label to the value of the property? Thanks FULL CODE: Nations class: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Nation_Simulator { public class Nations { public string name { get; set; } public string TypeOfGovernment { get; set; } public string RulingParty { get; set; } public string HeadOfState { get; set; } public int military { get; set; } public int diplomacy { get; set; } public int industry { get; set; } public int prestige { get; set; } public byte stability { get; set; } public Nations(string Name, string Government, string Party, string HeadState, int mil, int dip, int ind, int prest, byte stab) { name = Name; TypeOfGovernment = Government; RulingParty = Party; HeadOfState = HeadState; military = mil; diplomacy = dip; industry = ind; prestige = prest; stability = stab; } Nations Italy = new Nations("Italy", "Authoritarianism", "Partito Nazionale Fascista", "Vittorio Emanuele III", 300, 700, 750, 400, 3); } }

19th Aug 2018, 12:03 PM
Vincenzo Visconti
Vincenzo Visconti - avatar
3 Réponses
+ 1
could you provide full code ? what is a type of the descriped variables? What is their access modifier? What error does the compiler show?
19th Aug 2018, 12:14 PM
Roman Khristoforov
Roman Khristoforov - avatar
+ 1
Vincenzo Visconti You need to convert Italy.mil to string like that: LblMil_Score.Text=Italy.military.ToString(); As I see "mil" is only constructor parameter.
19th Aug 2018, 5:15 PM
Roman Khristoforov
Roman Khristoforov - avatar
0
Home Class: namespace Nation_Simulator { public partial class HomePage : Form { public HomePage() { InitializeComponent(); } protected bool Ger_active = false; protected bool GB_active = false; protected bool Fra_active = false; protected bool Ita_active = false; private void Add_Items_Italy(object sender, EventArgs e) { LstNationDetails.Items.Clear(); LstNationDetails.Items.Add("Name: Italy"); LstNationDetails.Items.Add("Government: Authoritarianism"); LstNationDetails.Items.Add("Ruling Party: Partito Nazionale Fascista"); LstNationDetails.Items.Add("Head Of State: Vittorio Emanuele III"); LstNationDetails.Items.Add("Military points: 300"); LstNationDetails.Items.Add("Diplomacy points: 700"); LstNationDetails.Items.Add("Industrial points: 750"); LstNationDetails.Items.Add("Prestige: 400"); LstNationDetails.Items.Add("Stability: 3"); Btn_Start.Enabled = true; Ita_active = true; } private void Btn_Start_Click(object sender, EventArgs e) { MainPanel.Visible = false; GamePanel.Visible = true; Btn_Start.Hide(); if(Ita_active==true) { Nation_Name.Text = "Italy"; Mil_Score.Text= (This is where i want italy's military score to be) } } } }
19th Aug 2018, 4:49 PM
Vincenzo Visconti
Vincenzo Visconti - avatar