use of using keyword in C#

 


# using keyword:- using keyword has two major uses:-

1.As a statement:-The using statement defines a scope at the end of which an object will be disposed.
Note:- Internally using keyword call the dispose method to dispose the I Disposable interface.

        public List<Student> GetSudent()
        {
            using (DbFirstProjectEntities _context=new DbFirstProjectEntities())
            {
                var students = _context.Students.ToList();
                return students;
            }            
        }


2.As a directive: Using keyword can be used to include a namespace in our program.

    using System.Text;

No comments:

Post a Comment