2016-12-10 4 views
-2

私はC#を学ぶのが初めてで、質問があります。ここで C#重複<k, v>

ACT 
21.0 
SAT 
478.9 
CLEP 
69.1 
ACT 32.0 

の下にど​​のように私は(任意の重複を削除)次のように辞書と表示するには、このTXTを解析しないように、私はテストとスコアとtxtファイルを持っている

ACT 21.0 
SAT 478.9 
CLEP 69.1 

は私が

を試みたものです
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.IO; 
using System.Text.RegularExpressions; 

namespace Generate 
{ 
    class generateInputStream 
    { 
     static void Main(string[] args) 
     { 
      FileManager objfileManager = new FileManager(); 
      FileStream fs = null; 

      Console.Write("Enter the file path: "); 

      while (fs == null) 
      { 
       string Path = Console.ReadLine(); 
       fs = objfileManager.OpenFile(Path); 
      } 
      int 

     } 

    } 

    public class FileManager 
    { 
     public FileStream OpenFile(string Path) 
     { 
      try 
      { 
       return new FileStream(Path, FileMode.Open, FileAccess.Read); 
      } 

      catch (Exception e) 
      { 
       Console.Write("Problem opening file {0}, please enter a valid path: ", Path); 
      } 
      return null; 
     } 

     public List<string> ReadLines(FileStream File) 
     { 
      List<string> text = new List<string>(); 
      try 
      { 
       var streamReader = new StreamReader(File); 

      } 
      catch (Exception e) 
      { 
       Console.Write(e.Message); 
      } 
      return text; 
     } 

     static readFileIntoDictionary() 
     { 
      StreamReader generateInputStream; 
      var streamReader = new StreamReader(); 

      SortedDictionary<string, double> dic = new SortedDictionary<string, double>(); 

      string Key = string.Empty; 
      double Value = 0.0; 


      while ((Key = streamReader.ReadLine())!= null) 
      { 
       Value = Convert.ToInt32(streamReader.ReadLine()); 

       dic.Add(Key, Value); 
      } 
      streamReader.Close(); 

      return dic; 
     } 

     static displayScoreData() 
     { 
      readFileIntoDictionary(); 
      foreach (KeyValuePair<string, double> pair in dic) 
      { 
       Console.WriteLine(pair.Key, "-",pair.Value); 
       } 
     } 
    } 
} 
+2

あなたは自分で宿題をする必要があります –

答えて

0

この方法は少しお手伝いします。ここでエラー処理は行われないので、ファイルは常に正しい形式であるとみなします。

public static KeyValuePair<string, decimal>? ReadPair (StreamReader sr) 
{ 
    if (sr.EndOfStream) return null; 

    string key = sr.ReadLine(); 
    decimal value = decimal.Parse (sr.ReadLine()); 

    return new KeyValuePair<string, decimal> (key, value); 
} 

私はあなたのための重複は、同じキーがわからないのですか?同じキー+値ですか?

関連する問題