日期:2014-05-18  浏览次数:20768 次

谁能帮我解释一下我的语句,先谢谢啦
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace MyConfig
{
  class Staticvariable:ConfigurationSection
  {
  [ConfigurationProperty("id")]
  public int ID 
  {
  get 
  {
  return (int)this["id"];
  }
  set 
  {
  this["id"] = value; 
  }
  }
  [ConfigurationProperty("Value")]
  public int ID
  {
  get
  {
  return (int)this["Value"];
  }
  set
  {
  this["Value"] = value;
  }
  }
  }

}


------解决方案--------------------
楼主发表于:2010-07-08 11:16:20using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace MyConfig
{
class Staticvariable:ConfigurationSection//自定义的配置节点
{
[ConfigurationProperty("id")]//有一个名字叫做id的配置特性,改特性的值会映射到这个类的ID这个Property上 ( id=123 ,那么这个类的实例的ID就会是123) 下同,但是这个类有点奇怪,为什么把id和value两个配置特性都映射到了ID上 public int ID
{
get
{
return (int)this["id"];
}
set
{
this["id"] = value;
}
}
[ConfigurationProperty("Value")]
public int ID
{
get
{
return (int)this["Value"];
}
set
{
this["Value"] = value;
}
}
}

}