This is a program to get all the letters in a string in a specified range (in this case characters 3 through 7 of the word 'kangaroo').
Why am i getting an error at line arr[i] = x[start+i];
?
I am not using Substring because my instructor wants us to figure out how to do it without it as an exercise.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MethodsPractice2
{
class Program
{
static char[] GetRangeOfCharacters(string word, int start, int end)
{
string x = word;
char[] arr = new char[end - start];
for (int i = 0; i < end; i++)
{
arr[i] = x[start + i];
}
return arr;
}
private static void Main(string[] args)
{
char[] endResult;
string word = "kangaroo";
int start = 3;
int end = 7;
endResult = GetRangeOfCharacters(word, start, end);
Console.WriteLine(endResult);
}
}
}