I am creating an object(obj below) in using and return that object as part of the function return.Will this cause any problem like object will be disposed before I try to us
If you need to return a Disposable object, you need to make sure that ALL code paths either return the object or dispose it. Note that an exception being thrown out of the function IS a valid code path. To cover this case, you probably want to wrap the segment of code between the creation and returning in a try-catch or try-finally to ensure that the object gets properly disposed if the return statement is not successfully reached.