C# learner
Active member
- Joined
- Dec 22, 2022
- Messages
- 40
- Programming Experience
- Beginner
This method when traced will parse out line and return the values in line to separate variables. When traced to the return everything is working fine. When passed back to the calling method the separate variables are null????
This is the method:
This is the calling method:
What am I doing wrong?
This is the method:
C#:
static (string RecordIndex, string tag, string IndividualInfo) LineBreakDown(string line, string RecordIndex, string tag, string IndividualInfo)
{
// using the split method parse line into lineParts array
string[] lineParts = line.Split(' ');
// Get the total number of elements
int TotalElements = lineParts.Count();
// if lineParts is not equal to null
if (lineParts != null)
{
// In each of the file records there are three space delimited fields. The information is used to parse into the method fields.
// no record in the file contains just one field
// The individual info needs to be combined into one field using the string.Join() method
switch (TotalElements)
{
// if the total elements is 2 then parse RecordIndex and tag then move blanks to IndividualInfo field and return control to calling method
case 2:
RecordIndex = lineParts[0];
tag = lineParts[1];
IndividualInfo = "";
return (RecordIndex, tag, IndividualInfo);
//break;
// if the total elements is 3 then parse RecordIndex, tag, and IndividualInfo fields and return control to calling method
case 3:
RecordIndex = lineParts[0];
tag = lineParts[1];
IndividualInfo = lineParts[2];
return (RecordIndex, tag, IndividualInfo);
// if the total elements is greater than 3 then parse the RecordIndex and tag and combine all Individual Info to IndividualInfo
default:
//ReadLine();
RecordIndex = lineParts[0];
tag = lineParts[1];
int ArrayCount = TotalElements - 2;
IndividualInfo = string.Join(" ", lineParts, 2, ArrayCount);
return (RecordIndex, tag, IndividualInfo);
}
}
// any problems with method
throw new NotImplementedException();
C#:
LineBreakDown (line = "", RecordIndex = "", tag = "", IndividualInfo = "");
Last edited by a moderator: