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.
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...
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.