⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hashfile.cs

📁 asp.net_Lesson5
💻 CS
字号:
using System;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;

public class HashFile
{
    public static Hashtable ReadHashtableFromFile(string fileName)
    {
        StreamReader reader = null;
        Hashtable table = new Hashtable();
        try
        {
            reader = File.OpenText(fileName);					
            string line;
            string[] words;
            while( (line = reader.ReadLine()) != null)
            {
                words = Regex.Split(line, ",");
                if(table[words[0]] == null)
                    table.Add(words[0], words[1]);
            }
            return table;
        }
        catch(FileNotFoundException e)
        {
            return table;
        }
        finally
        {
            if(reader != null)
                reader.Close();
        }
    }
        
    public static void WriteHashtableToFile(Hashtable table, string fileName)
    {
        StreamWriter writer = null;
        try
        {
            writer = File.CreateText(fileName);
            foreach( string key in table.Keys)
            {
                writer.WriteLine("{0},{1}", key, table[key].ToString());
            }
        }
        finally
        {
            if(writer != null)
                writer.Close();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -