Friday 6 June 2014

How do you retrieve the last element of an array in C#?

string strCmbMissingValue="India is a great country in this world";

 string[] arrCmbMissingVal = strCmbMissingValue.Split(' ');

string strCmbMissingDataType = arrCmbMissingVal[arrCmbMissingVal.Length - 1];


you can use LINQ

string[] stringArray = { "India ", "great ", "country ","in", "this " "world" };
var last=stringArray.Last();
var first=stringArray.First();

No comments:

Post a Comment