首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

帮这个方法如何调用呀

2011-12-22 
帮这个方法怎么调用呀?usingSystemnamespacePBC.Business{///summary///Branch的摘要说明。////summary

帮这个方法怎么调用呀?
using   System;

namespace   PBC.Business
{
///   <summary>
///   Branch   的摘要说明。
///   </summary>
public   class   Branch
{
private   string   _code;
private   string   _name;
private   Branch(string   code,   string   name)
{
_code   =   code;
_name   =   name;
}

public   string   Code
{
get   {return   _code;}
}

public   string   Name
{
get   {return   _name;}
}

#region   静态方法
public   static   Branch[]   _allBranchs   =   new   Branch[31];

public   static   Branch[]   GetAllBranchs()
{
if   (_allBranchs[0]   ==   null)
{
lock(_allBranchs)
{
if   (_allBranchs[0]   ==   null)
{
string[]   codes   =   { "100 ",   "200 ",   "210 ",   "220 ",   "230 ",   "240 ",   "250 ",   "270 ",   "280 ",   "290 ",   "311 ",   "351 ",   "371 ",   "431 ",   "451 ",   "471 ",   "531 ",   "551 ",   "571 ",   "591 ",   "731 ",   "771 ",   "791 ",   "851 ",   "871 ",   "891 ",   "898 ",   "931 ",   "951 ",   "971 ",   "991 "};
string[]   names   =   { "北京 ",   "广东 ",   "上海 ",   "天津 ",   "重庆 ",   "辽宁 ",   "江苏 ",   "湖北 ",   "四川 ",   "陕西 ",   "河北 ",   "山西 ",   "河南 ",   "吉林 ",   "黑龙江 ",   "内蒙古 ",   "山东 ",   "安徽 ",   "浙江 ",   "福建 ",   "湖南 ",   "广西 ",   "江西 ",   "贵州 ",   "云南 ",   "西藏 ",   "海南 ",   "甘肃 ",   "宁夏 ",   "青海 ",   "新疆 "};
for(int   i=0;   i <_allBranchs.Length;   i++)
_allBranchs[i]   =   new   Branch(codes[i],   names[i]);
}
}
}

Branch[]   allBranchs   =   new   Branch[31];
_allBranchs.CopyTo(allBranchs,   0);
return   allBranchs;
}

public   static   Branch   GetBranch(string   code)
{
if   (code   ==   null)
throw   new   ArgumentNullException( "code ");

Branch[]   allBranchs   =   Branch.GetAllBranchs();
for   (int   i=0;   i <   allBranchs.Length;   i++)
{
if   (allBranchs[i].Code   ==   code)
return   allBranchs[i];
}
throw   new   ArgumentOutOfRangeException( "code ",   "无效的省公司代码 ");
}
#endregion
}
}

现在有个listbox怎么样和这个类里的那个数据绑定呀??


[解决办法]
listbox1.DataSource = Branch.GetAllBranchs();


listbox1.DataTextField = "Name ";
listbox1.DataValueField = "Code ";
listbox1.DataBind();

热点排行