M
Mike Labosh
Below, I want the first constructor to pass a default to the second
constructor, but I can't seem to work out the syntax to do so. For example,
in VB.NET I can do this:
Sub New()
Me.New(passDefaultStuff)
End Sub
Sub New(stuff)
'do stuff
End Sub
Here is my class in C#:
public enum DataProvider {Odbc, OleDb, Oracle, SqlServer}
public abstract class DataProcessor {
private DataProvider _provider = DataProvider.SqlServer;
private string _connectionString;
public DataProcessor() {
// I want to have the default constructor pass
// a default value to the other constructor
DataProcessor(DataProvider.SqlServer);
~~~~~~~~~ <-- blue error line when I try to build:
"DataProcessor denotes a class, which is not valid
in the given context"
}
public DataProcessor(DataProvider dataProvider) {
this.Provider = dataProvider;
try {
this.ConnectionString =
ConfigurationSettings.AppSettings["connectionString"];
}
catch {} // Throw away
}
public string ConnectionString {
get {return _connectionString;}
set {
if (value == null | value.Length == 0)
throw new ArgumentNullException("connectionString",
"connectionString cannot be null / Nothing / ZLS");
_connectionString = value;
}
}
}
constructor, but I can't seem to work out the syntax to do so. For example,
in VB.NET I can do this:
Sub New()
Me.New(passDefaultStuff)
End Sub
Sub New(stuff)
'do stuff
End Sub
Here is my class in C#:
public enum DataProvider {Odbc, OleDb, Oracle, SqlServer}
public abstract class DataProcessor {
private DataProvider _provider = DataProvider.SqlServer;
private string _connectionString;
public DataProcessor() {
// I want to have the default constructor pass
// a default value to the other constructor
DataProcessor(DataProvider.SqlServer);
~~~~~~~~~ <-- blue error line when I try to build:
"DataProcessor denotes a class, which is not valid
in the given context"
}
public DataProcessor(DataProvider dataProvider) {
this.Provider = dataProvider;
try {
this.ConnectionString =
ConfigurationSettings.AppSettings["connectionString"];
}
catch {} // Throw away
}
public string ConnectionString {
get {return _connectionString;}
set {
if (value == null | value.Length == 0)
throw new ArgumentNullException("connectionString",
"connectionString cannot be null / Nothing / ZLS");
_connectionString = value;
}
}
}