![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Dec 2006
Posts: 7
Rep Power: 0
![]() |
Cannot assign 'Add' because it is a 'method group'
Beating my head against the wall on this one. Trying to write a simplified version of a combat routine (to make sure I have all the basic pieces working).
But getting stuck with just getting the basics done and drawing a blank on what I can do to solve this last issue. And hoping I can get some help. To start with, I have a windows form where some info is entered: namespace BasicCombatForm
{
public partial class DataEntry : Form
{
int[] fighter1 = new int[2];
int[] fighter2 = new int[2];
public DataEntry()
{
InitializeComponent();
}
private void btnBegin_Click(object sender, EventArgs e)
{
string nameFighter1 = txtFighter1Name.Text;
string nameFighter2 = txtFighter2Name.Text;
fighter1[0] = Convert.ToInt16(txtFighter1Atk.Text);
fighter1[1] = Convert.ToInt16(txtFighter1Def.Text);
fighter2[0] = Convert.ToInt16(txtFighter2Atk.Text);
fighter2[1] = Convert.ToInt16(txtFighter2Def.Text);
Fight war = new Fight();
Display show = new Display();
show.showFight(war.newFight(nameFighter1, nameFighter2, fighter1, fighter2));
}
}
}Next I have the class that handles the combat routine: namespace BasicCombatForm
{
public class Fight
{
public string[] newFight(string nameFighter1, string nameFighter2, int[] fighter1, int[] fighter2)
{
Random objRan = new Random();
int roll1 = objRan.Next(1, 21);
int roll2 = objRan.Next(1, 21);
int fighter1Atk = fighter1[0] + roll1;
int fighter1Def = fighter1[1] + roll1;
int fighter2Atk = fighter2[0] + roll2;
int fighter2Def = fighter2[1] + roll2;
string[] result = new string[2];
if (fighter1Atk > fighter2Def)
result[0] = nameFighter1 + " scores a hit on " + nameFighter2;
else
result[0] = nameFighter1 + " misses " + nameFighter2;
if (fighter2Atk > fighter1Def)
result[1] = nameFighter2 + " scorese a hit on " + nameFighter1;
else
result[1] = nameFighter2 + " misses " + nameFighter1;
return result;
}
}
}And last I have a simple output form I want to write the results to: namespace BasicCombatForm
{
public partial class Display : Form
{
public Display()
{
InitializeComponent();
}
public object showFight(string[] result)
{
lstDisplayFight.Items.ToString = result[0];
lstDisplayFight.Items.Equals = result[1];
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}After all is said and done, the last issue I am having is at the writing to the lstDisplayFight listbox. I keep coming back to the compile error that tells me that .Add or .Equals or any other function I try, cannot assign because it is a 'method group'. And I have not been able to find anything that helps clear up exactly what my issue is. Am I just going about this the wrong way? Or is there something else I can do? (Of course, I don't even know if the rest of this is going to work either...) Thanks all. Jarod |
|
|
|
|
|
#2 |
|
Sexy Programmer
|
You use the Items property and then the Add method.
ListBox b = new ListBox();
b.Items.Add(new string("wtf?!?!");ListBox b = new ListBox();
...after doing w/e to the listbox
int length = b.Count;
string strArray = new string[length]
for(int x = 0; x < length; x++)
strArray[x] = b.Items[x]; //gets item in list at index xListBox b = new ListBox();
string[] strArray = new string[10];
...
foreach(string str in strArray)
b.Items.Add(str);Hope this helps. Holla if you don't understand.
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Method not returning string | csrocker101 | C# | 1 | Apr 6th, 2007 6:45 PM |
| How to invoke static method from a Class object? | smith.norton | Java | 1 | Oct 5th, 2006 3:00 AM |
| DiveLog.java tutorial help | Arenlor | Java | 2 | Apr 26th, 2006 10:11 AM |
| Median/Mode in arrays? {Need help} | Java|Tera | Java | 27 | Nov 29th, 2005 10:50 AM |
| Debug recursion method() | pr0gm3r | Java | 3 | Oct 11th, 2005 12:33 PM |