我怎样才能返回Dictionary <string,string>值

时间:2017-06-11 11:16:54

标签: c# asp.net asp.net-mvc-3 dictionary datareader

Query类返回应返回要在主类

中重试的Dictionary
        class Query
        {
            public Dictionary<string, string> RunQueryWithParameters(string sim_input,string CommandTxt, Dictionary<string, string> parameters)
            {

                        OracleDataReader reader = cursCmd.ExecuteReader();
                        if(reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                ods_columns.Add("mob_no", reader.GetString(0));                        
                                ods_columns.Add("card_no", reader.GetString(1));
                                ods_columns.Add("account", reader.GetString(2));
                                ods_columns.Add("name", reader.GetString(3));
                                reader.NextResult();
                            }
                        Console.ReadLine();
                        reader.Close();
                        reader.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.ReadLine();                  
                    }

                    conn.Close();
                }
                return columns;
            }        
        }

我试图在主类函数中调用 RunQueryWithParameters

但没有返回任何价值。请帮助#

   static void main()
    {
        Dictionary<string, string> result=new Dictionary<string,string>;
        sting input="test";
        Query test=new Query();
        Query.RunQueryWithParameters(input,string "GET_DOC_DATA", result);
        console.writeline(result["mob_no"]);
        console.writeline(result["card_no"]);
        console.writeline(result["account"]);
        console.writeline(result["name"]);
    }

1 个答案:

答案 0 :(得分:0)

直接使用ToDictionary方法。

var result = 
  // as Jon Skeet pointed out, OrderBy is useless here, I just leave it 
  // show how to use OrderBy in a LINQ query
  myClassCollection.OrderBy(mc => mc.SomePropToSortOn)
                   .ToDictionary(mc => mc.KeyProp.ToString(), 
                                 mc => mc.ValueProp.ToString(), 
                                 StringComparer.OrdinalIgnoreCase);