[英]How to store a string from user input in an array to perform search operation on it in C#?
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() :如果您希望它以数组形式返回字符串的字符,请使用String.ToCharArray() :
public char[] burgers(string code)
{
return code.ToCharArray();
}
Seems kinda pointless now to put that into a function, though...现在将它放入 function 似乎有点毫无意义,尽管......
The return type has a problem.返回类型有问题。 Your function should have a return type of string[].
你的 function 应该有一个字符串 [] 的返回类型。
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.