Can you use an if statement with an overload constructor

  • Thread starter Thread starter sparks
  • Start date Start date
S

sparks

I had the bright idea of using if/else to call different constructors based on
a web form and what the user entered.

=======================================
IF I DECLARE this here everything works fine...
====>>>> Member member = new Member();
=======================================
public void Button1_Click(object sender,System.EventArgs e)
{
if (ContractNumber.Text =="")
{
Warning.Visible=true;
Warning.Text = "you Must put in a Contract Number to continue";
}
else
{
Warning.Visible=false;


=======================================
=======================================
THE PROBLEM COMES HERE...HOW TO USE AN OVERLOAD FUNCTION IN
THIS WAY.
THE RECORD1 GOES OUT OF SCOPE AFTER THE CLOSING }
SO THE CALLS TO THE VARIABLES AFTER THIS STATEMENT WILL NEVER BE
SEEN..

if(fee.Text!="" || memvalidation.Text!="")
{
====>>>> Member record1 = new Member(fee.Text,memvalidation.Text,Name.Text,barcode.Text,Address.Text,phone.Text);
}
=======================================
=======================================

Response.Write ("<br>" +record1.getName());
Response.Write ("<br>" +record1.getAddress());
}


is there any way to do conditional checks with overload constructors?

I can't figure out how to make decisions based on user input so I can populate a class and its parent class
ANY help or pointers or flames are very welcome.
I am stumped

thanks again
sparks
 
You can declare a reference without pointing it at an object.

Member member = null;
if( foo == bar && quux == baz)
{
member = new Member(42);
}
else
{
member = new Member("Hello World");
}

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<[email protected]>

I had the bright idea of using if/else to call different constructors based on
a web form and what the user entered.
 
Back
Top