I want to assign multiple variables at once in c#. I know I can assign each variable to the index of an array but am wondering if there is another alternative. The sample code I am working on is as follows:
I am using the following code to find the line with variables and return that line:
static public string linqalternative(string textfind1)
{
var nextLine = File.ReadLines(FILENAME)
.SkipWhile(line => !line.Contains(textfind1))
.Skip(1)
.First();
string linqalternative = nextLine;
return linqalternative;
}
Then I am calling the above function in the main subroutine as follows: The line has multiple values and it is stored in an array. Then I want new variables to be assigned the values of that array.
// Read Card C4
string stringC4 = linqalternative("C4 ISLTMT ISSSMMT");
string[] C4values =
stringC4.Split((string[])null, StringSplitOptions.RemoveEmptyEntries);
int ISLTMT = int.Parse(C4values[0]);
int ISSSMMT = int.Parse(C4values[1]);
int ISLTMTS = int.Parse(C4values[2]);
int ISIA = int.Parse(C4values[3]);
float RPIA = float.Parse(C4values[4]);
float RSQMIA = float.Parse(C4values[5]);
int ITRMIA = int.Parse(C4values[6]);
int ISAVEC = int.Parse(C4values[7]);
Can I assign all the variables shown above in a line or two or that is the only alternative ?