Reputation: 52
public class CellPhoneMessagingController : ApiController
{
[HttpGet]
[Route("api/CellPhoneMessaging/{code}")]
public string burgers(string code)
{
string userCode = code;
char[] ch = new char[userCode.Length];
for (int i = 0; i < ch.Length; i++) {
ch[i] = userCode[i];
}
return ch;
}
}
I tried this but it is not returning the ch. Note: I am new in programming.
Upvotes: 0
Views: 78
Reputation: 36
The return type has a problem. Your function should have a return type of string[].
public class CellPhoneMessagingController : ApiController
{
[HttpGet]
[Route("api/CellPhoneMessaging/{code}")]
public string[] burgers(string code)
{
string userCode = code;
char[] ch = new char[userCode.Length];
for (int i = 0; i < ch.Length; i++) {
ch[i] = userCode[i];
}
return ch;
}
Upvotes: 1
Reputation: 39132
If you want it to return the characters of the string as an array, then use String.ToCharArray():
public char[] burgers(string code)
{
return code.ToCharArray();
}
Seems kinda pointless now to put that into a function, though...
Upvotes: 3