I am trying to implement IDisposable in a sample program. If I use SqlConnection class inside a using block statement, it will automatically dispose it.  public int testCon() {     using (SqlConnection conn = new SqlConnection("Conn string"))     {         using (SqlCommand cmd = conn.CreateCommand())         {             conn.Open();             cmd.CommandText = "SELECT COUNT(1) FROM Carsd";              return (int)cmd.ExecuteScalar();         }     } }   I have created a class and implemented IDisposable. I have created a new instance inside a using block statement.   class Program  {     static void Main(string[] args)     {         testDispose objTestDispose;          using (objTestDispose = new testDispose())         {             objTestDispose.UserName = "testUser";             objTestDispose.PassWord = "testPassword";                                         }          Console.WriteLine("Check obj of testDispose Class" + objTestDispose.UserName);         Console.WriteLine("Check obj of testDispose Class" + objTestDispose.PassWord);         Console.ReadLine();      }         }  public class testDispose : IDisposable {     public string UserName { get; set; }     public string PassWord { get; set; }      public void Dispose()     { }               }   I believe, using block automatically call dispose method. So, if I am create a new instance in using block, it would be dispose after existing using block. But, still I am able to access objTestDispose object outside of the using block.WHY?   Please suggest.  UDPATE   Mr.BWA..Thank you for the making my question duplicate. but you should know I am a student and learning. I have this question in my mind so I have asked here.  **You can not say that IDisposable interface only for unmanaged resources.**I can also remove managed resources. It depends on the situation. As per the below  -      What if your object has allocated a 250MB System.Drawing.Bitmap (i.e. the .NET managed Bitmap class) as some sort of frame buffer? Sure, this is a managed .NET object, and the garbage collector will free it. But do you really want to leave 250MB of memory just sitting there – waiting for the garbage collector to eventually come along and free it? What if there's an open database connection? Surely we don't want that connection sitting open, waiting for the GC to finalize the object.      If the user has called Dispose() (meaning they no longer plan to use   the object) why not get rid of those wasteful bitmaps and database   connections?      So now we will:      get rid of unmanaged resources (because we have to), and get rid of   managed resources (because we want to be helpful)
I know from reading  that the "primary" use of the IDisposable interface is to clean up unmanaged resources.  To me, "unmanaged" means things like database connections, sockets, window handles, etc.  But, I've seen code where the Dispose() method is implemented to free managed resources, which seems redundant to me, since the garbage collector should take care of that for you.  For example:  public class MyCollection : IDisposable {     private List&lt;String&gt; _theList = new List&lt;String&gt;();     private Dictionary&lt;String, Point&gt; _theDict = new Dictionary&lt;String, Point&gt;();      // Die, clear it up! (free unmanaged resources)     public void Dispose()     {         _theList.clear();         _theDict.clear();         _theList = null;         _theDict = null;     }   My question is, does this make the garbage collector free memory used by MyCollection any faster than it normally would?  edit:  So far people have posted some good examples of using IDisposable to clean up unmanaged resources such as database connections and bitmaps.  But suppose that _theList in the above code contained a million strings, and you wanted to free that memory now, rather than waiting for the garbage collector.  Would the above code accomplish that?
Does the integral $\int_{1}^{\infty} \sin(x\log x) \,\mathrm{d}x$ converge? Prove that If $m'$ is a common multiple of $s$ and $t$, then $m | m'$. Here $m$ is the LCM of $s$ and $t$.    Although the statement is intuitively clear to me I don't know how to prove. Split Data Based on Year in a Visual force Page PDF Short story identification: society partitioned off by high wall Why is Android refusing to resolve DNS records pointing to internal IP addresses? Intuition on the Kullback–Leibler (KL) Divergence Polynomials with integer coefficients such that $p(a)=b,p(b)=c,p(c)=a$ While studying polynomials a question struck in my mind that  To have a polynomial $p(x)$ with integer coefficients and $a,b,c$ are three distinct integers, then is it possible to have $$p(a)=b$$$$p(b)=c$$$$p(c)=a$$ How can I mute the YouTube app while playing music on another player? Why is wine made 'from' grapes, but tables are made 'of' wood? (1) Wine is an alcoholic beverage made from fermented grapes or other fruits. (Wikipedia) (2) Tables were made of marble or wood and metal (typically bronze or silver alloys), sometimes with richly ornate legs. (Wikipedia)  Why is 'from' used in (1), whereas 'of' is used  in (2)? Is it a stylistic choice whether to use 'of' or 'from'? Or, in case of chemical changing, differently from changing in shape only, 'from' is preferable? Anime about a boy and a girl who ride ostrich-like creatures through a valley I can not remember much but I have had this film in my head for years I searched everything I can remember on every website I can think of.  I don't remember the exact story but I'll list everything about it can   Apocalyptic future possibly Two main characters: a boy and a girl riding ostrich-like creatures through a valley An old blind lady that senses things Crashed spaceship looking like a submarine Giant creatures looks like yaks with blue eyes, whose eyes turn red when something is about to happen The old lady says "Some say they went to the stars" while looking at the spaceship The two main characters do something and their eyes turn blue in the distance and the village cheers   This film is at least ten years old and I would appreciate it so much if you knew anything about it, or could help me find the title. How to see download count of an Android app on Google Play store? I cannot see the download counts of one app on Google Play.   How can we know that number of one app? Whoa! What is this "Linked" thing? As per the title, what is this new feature? How can I get the DateTime for the start of the week? Any command that starts with $ returns  command not found   How can I fix this?  I am  using 16.10 Ubuntu. Irreducible polynomial is always separable in char 0 field I have a Laars gas boiler that has 3 heating zones. I want to replace the old mercury honeywell tstat on the 1st floor (heat only) with a newer honeywell RTH9580 wifi model. I've taken pictures of my entire system, labeled the wires in the pics to indicate the associated connections, and included the Laars wiring diagram.  There is a transformer mounted on the wall near the boiler that is wired in-line to the system (power from the panel --> into the emergency boiler switch --> into the wall transformer --> then to the boiler (low water cut off and boiler circuitry).  There is also a transformer within the boiler circuitry itself.  Can someone tell me the best method (proper preferred, not necessarily easiest) to connect the C wire? Disable emojicons introduced with WP 4.2 So WP 4.2 introduced emojis (smileys) that basically adds JS and other junk all over your pages. Something some people may find shocking. How does one completely erase all instances of this? I am currently studying  answer on the Moore-Penrose pseudoinverse and the Euclidean norm by the user &quot;Etienne dM&quot;. The first point of their answer proceeds as follows:  Let $x$ be $A^+y$.  Let me begin by the second point. For all $z$, we have: \begin{align} \lVert Az-b \rVert_2^2 &amp;= \lVert Ax-b \rVert_2^2 + \lVert A(z-x) \rVert_2^2 + 2 (z-x)^TA^T(Ax-b)\\ &amp; \geq  \lVert Ax-b \rVert_2^2 + 2 (z-x)^TA^T(Ax-b) \end{align} Moreover, because $(AA^+)^T = AA^+$, $$ A^T(Ax-b) = ((AA^+)A)^Tb - A^Tb = 0$$ Thus, we prove that for all $z$, $\rVert Az-b \lVert_2^2 \geq\rVert Ax-b \lVert_2^2$, that is to say $A^+b$ is as close as possible to $y$ in term of the Euclidian norm $\lVert Ax-b\rVert_2$.   I realise that $x = A^+ y$, but I don't understand how any of this implies that &quot;$A^+ b$ is as close as possible to $y$ in terms of the Euclidean norm $\lVert Ax-b\rVert_2$&quot;. I would greatly appreciate it if people would please take the time to explain this to me. Capitalize fields of study? Is it possible to upgrade the graphics card in modern laptops? As there's no definitive answer to this, and I would prefer not to be too specific about particular models, what are the things that determine whether this is possible or not?   What expansion slots would the laptop require to do this? How can you find out if a motherboard/chipset supports upgrades?  Is heat an issue? Could it void the warranty? How is battery life affected?