System.IO.StreamReader.Dispose C# (CSharp) Method

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void
        protected override void Dispose(bool disposing)
        {
            // Dispose of our resources if this StreamReader is closable.
            // Note that Console.In should be left open.
            try
            {
                // Note that Stream.Close() can potentially throw here. So we need to 
                // ensure cleaning up internal resources, inside the finally block.  
                if (!LeaveOpen && disposing && (_stream != null))
                {
                    _stream.Close();
                }
            }
            finally
            {
                if (!LeaveOpen && (_stream != null))
                {
                    _stream = null;
                    _encoding = null;
                    _decoder = null;
                    _byteBuffer = null;
                    _charBuffer = null;
                    _charPos = 0;
                    _charLen = 0;
                    base.Dispose(disposing);
                }
            }
        }

Usage Example

Example #1
1
        static void Main(string[] args)
        {
            StreamReader sr = new StreamReader(Console.OpenStandardInput());
            string input = sr.ReadToEnd();
            sr.Dispose();

            JavaScriptSerializer ser = new JavaScriptSerializer();
            dynamic json = ser.DeserializeObject(input);
            for (int i = 1; i < json.Length; i++)
            {
                dynamic block = json[i];
                string blockType = block[0];
                Dictionary<string, object> blockAttr = block[1];

                for (int j = 2; j < block.Length; j++)
                {
                    dynamic span = block[j];
                    string spanType = span[0];
                    string text = span[1];
                    Console.Write(text);
                }

                Console.WriteLine();
                Console.WriteLine();
            }
        }
All Usage Examples Of System.IO.StreamReader::Dispose