Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this code works fine.
- public sealed class MyObject
- {
- static ExtDeviceDriver devDrv;
- public MyObject()
- {
- devDrv = new ExtDeviceDriver();
- }
- public void Connect()
- {
- devDrv.connect();
- }
- }
- //this code causes exception.
- public sealed class MyObject
- {
- static ExtDeviceDriver devDrv;
- public MyObject()
- {
- // do not create devDrv here.
- //devDrv = new ExtDeviceDriver();
- }
- public void Connect()
- {
- if (devDrv == null)
- devDrv = new ExtDeviceDriver();
- devDrv.connect();
- }
- }
- public class MyObject
- {
- static ExtDeviceDriver devDrv;
- static MyObject()
- {
- devDrv = new ExtDeviceDriver();
- }
- public void Connect()
- {
- devDrv.connect();
- }
- }
Add Comment
Please, Sign In to add comment