Reputation: 732
public partial class _Default : System.Web.UI.Page
{
char[] chname1=new char[20];
char[] chname2=new char[20];
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btsubmit_Click(object sender, EventArgs e)
{
chname1 = Convert.ToChar(txtname1.Text);
chname2 = Convert.ToChar(txtname2.Text);
Response.Write(chname1.ToString().Length+"---"+chname2.ToString().Length);
}
}
This is a simple asp.net code,i cannot convert char to char array... How to find the character at ch[i] th position?
Upvotes: 1
Views: 11617
Reputation: 8920
What is it you are trying to achieve? Are your txtname1 and textname2 textboxes? In that case why bother with an array of chars. Just use strings and substring functionality.
Upvotes: 0
Reputation: 57192
You can use the ToCharArray()
method of the string
class:
chname1 = txtname1.Text.ToCharArray();
But what are you trying to do exactly? if you only need the length, there is no need to convert to char[], just use
txtname1.Text.Length;
Upvotes: 3
Reputation: 1500355
You've got a string, and you're trying to convert it to char
, and then assign the result to a char[]
variable.
Are you sure you don't just want:
chname1 = txtname1.Text.ToCharArray();
Note that calling ToString()
on a char[]
probably doesn't do what you want it to either... converting a char[]
to a string
is normally done via new string(char[])
.
Upvotes: 6
Reputation: 47978
To convert a string
to char
array:
chname1 = txtname1.Text.ToCharArray()
Upvotes: 1