我正在使用Xamarin Studio,我正在尝试获取用户输入的内容并使用大写字母中的第一个字符进行翻译,但text.First()
会给我Unknown resolve error
。在同一个文件中,我已经成功使用了Linq表达式。
public void TextChanged(String text)
{
if (!String.IsNullOrEmpty (text))
text = text.First().ToString().ToUpper() + text.Substring(1); //Unknown resolve error
}
答案 0 :(得分:0)
你可以尝试这个:
text = Char.ToUpper(text.First())+text.Substring(1);
答案 1 :(得分:0)
在aspx页面上
<form id="form1" runat="server">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>enter code here
Name:
</td>
<td>
<asp:TextBox ID="txtName" runat="server" Text=""/>
</td>
</tr>
<tr>
<td>
Age:
</td>
<td>
<asp:TextBox ID="txtAge" runat="server" Text="" />
</td>
</tr>
<tr>
<td>
<asp:Button ID="btnSubmit" Text="Submit" runat="server" />
</td>
</tr>
</table>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/json2/20130526/json2.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=btnSubmit]").click(function () {
var obj = {};
obj.name = $.trim($("[id*=txtName]").val());
obj.age = $.trim($("[id*=txtAge]").val());
$.ajax({
type: "POST",
url: "FirstUpper.aspx/SendParameters",
data: JSON.stringify(obj),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
alert(r.d);
}
});
return false;
});
});
</script>
</form>
在cs页面上
[System.Web.Services.WebMethod]
public static string SendParameters(string name, int age)
{
if (!String.IsNullOrEmpty(name))
name = name.First().ToString().ToUpper() + name.Substring(1);
return string.Format("Name: {0}{2}Age: {1}", name, age, Environment.NewLine);
}
}