I have a scenario in which I have two new objects in which only one needs to be initialized according to the condition.
But I use the "using" block statement to initialize a new object.
How can i achieve this? Please refer to the scenario below.
int a;
string b;
if()
{
using(MyClass c1 = new MyClass(a))
{
SomeMethod();
}
}
else
{
using(MyClass c1 = new MyClass(b)
{
SomeMethod();
}
}
Is there a better way to achieve this in one condition or in some other way to reduce the code? because I call the same method in both conditions.
Thanks in advance.
Regards, Anish
source
share