Build with an Azure free account. Get USD200 credit for 30 days and 12 months of free services.

Start free today

C# Language Highlights: Using Declarations

Play C# Language Highlights: Using Declarations

The Discussion

  • User profile image
    I really like this feature of C# 8. Got a question. What if you do something like this at the class level of a class:

    using DbContext myContext = new OurDatabaseContext();

    Now, there's an open Entity Framework DbContext at a class level. Does it remain open throughout the lifetime of the class instance? Or does it get closed after some code within the class uses it for something?
  • User profile image

    Constructor in class is just a function called on creation, it doesn't matter what lifetime you have. And when you go out from scope of this function you drop your session. Therefore you session will be valid only in construction body (scope).

  • User profile image
    Not clear

Add Your 2 Cents