hisanth nithi

hisanth nithi

  • NA
  • 30
  • 9k

Dynamically Create instance for class

Jul 6 2019 7:13 AM
Hi i have 2 class (YarnBLL, DyingBLL) with same property.
 
i need to create a instace based on switch case
  1. public String insave(String name)  
  2. {  
  3.     var obj;  
  4.     switch (name)  
  5.     {  
  6.         case "YARN":  
  7.             obj = new YarnBLL();  
  8.             break;  
  9.         case "WEAVING":  
  10.             obj = new DyingBLL();  
  11.             break;  
  12.         default:  
  13.             break;  
  14.     }   
  15.   obj.InDate = Utils.ConvertStringToDate(txtDate.Text);  
  16.   obj.CategoryName = ddlCategory.SelectedItem.ToString();  
  17.   obj.Save();
  18. }  
 Here i have an error in
    var obj;
 it shows 
Error 1 Implicitly-typed local variables must be initialized

Answers (3)