How can we get the middle element in an array?
Example code:
string[] source = txtInput.Text.Split(',');
int[] nums = new int[input.Length];
for (int i = 0; i < source.Length; i++)
{
nums[i] = Convert.ToInt32(source[i]);
}
int first=nums[0];
int mid=///how is it?
Like this:
You take the size of the array (
nums.Length), divide by two to get the index in the middle and use that index.