Concatenate the values

Murugavelmsc
Posted by Murugavelmsc under C# category on | Points: 40 | Views : 824
class Program
{
static void Main(string[] args)
{

Console.WriteLine("Enter input values seperated by comma");
string val = Console.ReadLine();

ArrayList inputval = new ArrayList();

// Split the input values and stored in arraylist
ArrayList spltval = new ArrayList(val.Split(','));
int i = 0;

// Convert the splitval to integer and stored in arraylist
for (i = 0; i < spltval.Count; i++)
inputval.Add(Convert.ToInt32(spltval[i]));

// Sort the arraylist
inputval.Sort();

Console.WriteLine("Input values after sorting");
Console.WriteLine("**************************");

for (i = 0; i < inputval.Count; i++)
Console.WriteLine(inputval[i]);

Console.WriteLine("Ouput values");
Console.WriteLine("************");

// Method call to Get the series result
GetResult(inputval, 0);

Console.ReadKey();
}

static private void GetResult(ArrayList arrval, int index)
{
// start value of the series
int startval = Convert.ToInt32(arrval[index]);

// end value of the series
int endval = Convert.ToInt32(arrval[arrval.Count - 1]);

int series = startval;
int i;

// Check the series
for (i = index; i < arrval.Count; i++)
{
int cmpval1 = int.Parse(arrval[i].ToString());
int cmpval2 = series++; //+i;

if (cmpval1 != cmpval2)
{
endval = int.Parse(arrval[i - 1].ToString());
break;
}
}

index = i;

// print result
Console.WriteLine(startval + "-" + endval);

// Recurssion - Call if the arraylist is completed or not
if (i < arrval.Count - 1)
GetResult(arrval, index);

return;
}
}

Comments or Responses

Login to post response