I am having trouble with a method that is called within main and is contained in the same class. The method is outputting a string value and my problem is trying to include references to arrays within the string message. I am getting the message
Only assignment, call, increment, decrement, and new object expressions can be used as a statement"
Along with invalid expression in regards to the comma and a whole bunch of ; expected all in regards to the following line:
searchResult = "Account #" + accountsarr[i] + " has a balance of {0:c}" + " for customer " + namesarr[i], balancesarr[i]";
all within the following method:
public static string searchAccounts(ref int AccountNumber, int[] accountsarr, double[] balancesarr, string[] namesarr)
{
bool isValidAccount = false;
int i = 0;
while (i < accountsarr.Length && AccountNumber != accountsarr[i])
{
++i;
}
if (i != accountsarr.Length)
{
isValidAccount = true;
}
string searchResult;
if (isValidAccount)
{
searchResult = "Account #" + accountsarr[i] + " has a balance of {0:c}" + " for customer " + namesarr[i], balancesarr[i]";
}
else
searchResult = "You entered an invalid account";
return searchResult;
}
So how do you return a string from a method that has references to array positions within the text that should be the string?
String.Format." + namesarr[i], balancesarr[i]";