1
Answer

global variable in c#

kobycool68

kobycool68

20y
2.6k
1
hey, i need help with c#. i want to define a global variable that all classes know this variable without doing 'new' in every class where i want to use this variable. this is my program - tell me whats wrong or what should i do? (pseudo code) public class AA { private static SqlConnection sqlCon; public AA()//constructor { sqlCon = new SqlConnection(); sqlCon.ConnectionString = "....."; } public SqlConnection con2 { get{return sqlCon;} set{SqlCon = value;} } } } when i try to use sqlCon in other classes there is an error: "Object reference not set to an instance of an object" class BB { AA a; public BB()//constructor { . . . . } void func1() { a.con2.open(); <----------- this is the error line .......... .......... } } thanking you in advance koby
Answers (1)