小编Sea*_*thy的帖子

C#中字典输出错误

从字典打印时,为什么要获取namespace.object的输出?

这是我的数据对象.

namespace MoleCalculator
{
    public class elementDO
    {
        public int AtomicNumber { get; set; }
        public string Symbol { get; set; }
        public string Name { get; set; }
        public decimal AtomicWeight { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是包含我字典的类

namespace MoleCalculator
{
public class elementDictionary
{
    public Dictionary<int, elementDO> periodic_Table = new Dictionary<int, elementDO>()
    {
        {1,new elementDO{AtomicNumber = 1,Symbol = "H",Name = "Hydrogen", AtomicWeight = 1.007825M}},
Run Code Online (Sandbox Code Playgroud)

这就是驱动它的原因

var elements = new elementDictionary().periodic_Table;
        Console.WriteLine(elements[1]);
Run Code Online (Sandbox Code Playgroud)

c# dictionary

-2
推荐指数
1
解决办法
67
查看次数

标签 统计

c# ×1

dictionary ×1