Reputation: 387
I created a class called Checker. This is the code:
namespace WindowsFormsApplication1
{
public class Checker
{
int CheckAdminEdit(Object Temp,int counter,int allow)
{
int _counter = counter;
int _allow = allow;
Admin _Temp = Temp as Admin;
foreach (Control c in _Temp.edit_admin.Controls)
{
if (c is TextBox)
{
TextBox textBox = c as TextBox;
if (textBox.Text.Equals(string.Empty))
{
_Temp.errorProvider1.SetIconPadding(textBox, 0);
_Temp.errorProvider1.SetError(textBox, "Field Empty");
_allow++;
}
else
{
_Temp.errorProvider1.SetIconPadding(textBox, 666);
if (textBox.Name == "textBox6")
{
if( CheckEmail(textBox.Text))
_Temp.errorProvider2.SetIconPadding(textBox, 666);
else
{
_Temp.errorProvider2.SetError(textBox, "Invalid email syntax");
_counter++;
}
}
}
}
}
return (allow + counter);
}
private bool CheckEmail(string EmailAddress)
{
string strPattern = "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
if (System.Text.RegularExpressions.Regex.IsMatch(EmailAddress, strPattern))
return true;
return false;
}
}
}
and in my form I'm trying to declare the class with :
Checker try = new Checker;
but the first Checker in underlined also the try the = sign and the ; sign saying that Only assignment, call, increment, decrement, and new object expressions can be used as a statement. Sorry if this is hard to understand, but I'm very thankful to those who can help:D
Upvotes: 0
Views: 6376
Reputation: 48558
You haven't used parenthesis ()
for calling constructor after new
operator. That's why you are getting Only assignment, call, increment, decrement, and new object expressions can be used as a statement
error.
Moreover try is a keyword which you cannot use as variable name.
You can do this
Checker @try = new Checker();
or
Checker _try = new Checker();
In that case you will have to access it like this
@try._counter = 0;
or
_try._counter = 0;
Upvotes: 4
Reputation: 7692
try
is a keyword, you should use another name for the object (or something like _try
)
Upvotes: 3