I am writing an application that needs to query multiple databases, so to standardize my connection strings, I wrote the following enum and method:
class Program
{
enum DBEnum { DB1, DB2, DB3, DB4, DB5 }
static void Main(string[] args)
{
using (CacheConnection myConnection = new CacheConnection())
{
myConnection.ConnectionTimeout = 9999;
myConnection.ConnectionString = DBSelect(DBEnum.DB1);
myConnection.Open();
}
}
public static string DBSelect(int i)
{
string connectionString = "";
switch (i)
{
case 0:
connectionString = *connection string*;
break;
case 1:
connectionString = *connection string*;
break;
case 2:
connectionString = *connection string*;
break;
case 3:
connectionString = *connection string*;
break;
case 4:
connectionString = *connection string*;
break;
default:
break;
}
return connectionString;
}
}
But the problem is that it isn't assigning a numeric value to the enum definitions.
According to MSDN, unless the enum is casted to a different data type, or the definitions are specifically defined, the definitions should have an int value starting with 0.
However intellisense gripes to me that the line:
myConnection.ConnectionString = DBSelect(DBEnum.DB1);
has invalid arguments, and if I say something like
int i = DBEnum.DB1;
it asks me if I'm missing a cast.
Thanks!