I have a function that counts the commas in each item of an array of string.
public int CommaCount(string[] sarray)
{
int count = 0;
int commas = 0;
for (int i = 0; i < sarray.Length; i++)
{
commas = sarray[i].Count(c => c == ',');
if (commas > count)
{
count = commas;
}
}
return count;
}
However I'd like for the function to not be able to modify the array, which is not const.
I would have thought the following might have done it, but I get intellisense errors with varying messages, the first of which is under the const word in function argument "Type Expected"
public int CommaCount(const string[] sarray)
{
int count = 0;
int commas = 0;
for (int i = 0; i < sarray.Length; i++)
{
commas = sarray[i].Count(c => c == ',');
if (commas > count)
{
count = commas;
}
}
return count;
}
Is there a way I can achieve such functionality?