1

I'm on Xamarin Studio and I'm trying to get what the user will input and translate it with the first char in upper Case, but text.First() give me Unknown resolve error. In the same file I'm already using Linq expression successfully.

public void TextChanged(String text)
{
    if (!String.IsNullOrEmpty (text))
        text = text.First().ToString().ToUpper() + text.Substring(1); //Unknown resolve error
}
Davide Quaglio
  • 751
  • 2
  • 11
  • 31
  • 2
    First() should give the first character.. Ex: "Pippo" will give "p". Yeah i know its immutable but in the method I'll do something else. – Davide Quaglio Jan 08 '15 at 08:38
  • It looks like a [Xamarin intellisense type issue](http://forums.xamarin.com/discussion/16061/unknown-resolve-error-in-library) - does your code compile? – StuartLC Jan 08 '15 at 08:40
  • @StuartLC Compiling give: `Error CS0411: The type arguments for method ``System.Linq.Queryable.First(this System.Linq.IQueryable)' cannot be inferred from the usage. Try specifying the type arguments explicitly (CS0411) (App)` – Davide Quaglio Jan 08 '15 at 08:44
  • You are doing check for `null`, there exists [another way](http://stackoverflow.com/q/3878820/1997232) to get first character: `text[0]`. – Sinatr Jan 08 '15 at 08:48
  • Yeah I know but this should work.. I'd like to know why there is this problem. – Davide Quaglio Jan 08 '15 at 08:51
  • @DQuaglio Your problem is different., http://stackoverflow.com/questions/16747774/how-do-i-add-a-system-core-dll-reference-to-my-project-in-xamarin-studio-monodev – Thirisangu Ramanathan Jan 08 '15 at 09:12
  • @Thirisangu I don't think, I'm already using in the same file a Linq expression. Also I already have the reference added by default. – Davide Quaglio Jan 08 '15 at 09:15
  • @DQuaglio what I can't get is the fact that `System.Linq.IQueryable` is used and not `System.Linq.IEnumerable` is used. A string implements `IEnumerable` not `IQueryable`. Honestly, quite weird. – Christos Jan 08 '15 at 09:57
  • Yeah it is, I tried in another project and this line of code works...Really weird. – Davide Quaglio Jan 08 '15 at 10:03

2 Answers2

0

You could try this one:

text = Char.ToUpper(text.First())+text.Substring(1);
Christos
  • 53,228
  • 8
  • 76
  • 108
0

On aspx page

<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>

on cs page

    [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);

    }

}