using的几种用法 C#
来源:互联网 发布:手机变音软件 编辑:程序博客网 时间:2024/05/18 03:25
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- using System.Data;
- using System.Data.SqlClient;
- using System.Xml;
- using Excel = Microsoft.Office.Interop.Excel;
-
- namespace statement
- {
-
- using F = System.Drawing.Font;
-
- class Program
- {
- static void Main(string[] args)
- {
-
- using (TextWriter writer = File.CreateText(@"E:\test.txt"))
- {
-
- F font = new F("宋体", 12);
- writer.WriteLine(font.Name.ToString() + font.Size.ToString());
- }
-
-
-
- TextWriter w = File.CreateText(@"E:\test.txt");
- try
- {
- F font = new F("宋体", 12);
- w.WriteLine(font.Name.ToString() + font.Size.ToString());
- }
- finally
- {
- if (w != null) w.Dispose();
- }
-
-
-
- TextReader r = File.OpenText("E://test.txt");
- using (r)
- {
- Console.WriteLine(r.ReadToEnd());
- }
-
-
-
- using (StreamReader reader = new StreamReader("1.txt"), reader2 = new StreamReader("2.txt"))
- {
-
- }
-
-
-
- using (SqlConnection conn = new SqlConnection())
- {
- using (SqlCommand cmd = new SqlCommand())
- {
-
-
- }
- }
-
-
-
- using (StreamReader reader = new StreamReader("1.txt"))
- using (StreamWriter writer = new StreamWriter("1.txt"))
- using (SqlConnection conn = new SqlConnection())
- using (SqlCommand cmd = new SqlCommand())
- {
-
-
- }
-
-
- }
- }
- }
-
-
-
-
-