发布网友 发布时间:2022-04-24 08:10
共3个回答
热心网友 时间:2023-10-09 02:34
public class UserInfo热心网友 时间:2023-10-09 02:35
List<UserInfo> list = new List<UserInfo>();热心网友 时间:2023-10-09 02:35
public class BUserInfo追答using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace demo
{
class Program
{
static void Main(string[] args)
{
BUserInfo info = new BUserInfo();
foreach (UserInfo user in info.GetAll())
Console.WriteLine(user.ToString());
Console.ReadLine();
}
}
[Serializable]
public class UserInfo
{
private string _username;
private string _userpwd;
public string UserName
{
get { return _username; }
set { _username = value; }
}
public string UserPwd
{
get { return _userpwd; }
set { _userpwd = value; }
}
public override string ToString()
{
return new StringBuilder(string.Format("UserName is {0},UserPwd is {1}", this.UserName, this.UserPwd)).ToString();
}
}
public class BUserInfo
{
public List GetAll()
{
List list = new List();
list.Clear();
UserInfo userinfo = new UserInfo();
userinfo.UserName = "css";
userinfo.UserPwd = "css";
//add1
list.Add(userinfo);
userinfo = new UserInfo();
userinfo.UserName = "admin";
userinfo.UserPwd = "admin";
//add2
list.Add(userinfo);
return list;
}
}
}
都测试过了,你自己看一样不一样。虽然是 引用类型,但是第二个你new过了,重新赋值了