using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
UserSet<User> users = new UserSet<User>();
users[0]=new User();
users[0].Name = "zhao";
users[0].Password = "123";
users[0].Login();
users[1] = new User();
users[1].Name = "song";
users[1].Password = "123";
users[1].Login();
Console.ReadLine();
}
}
//定义一个类
class User
{
private string name = string.Empty;
private string password = string.Empty;
public string Name
{
get { return name; }
set { name = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public void Login()
{
Console.WriteLine("name{0},password{1}",Name,password);
}
}
//定义一个索引器访问类
class UserSet<T>
{
private T[] arr = new T[10];
public T this[int i]
{
get { return arr[i]; }
set{arr[i]=value;}
}
}
}
C#索引器
最新推荐文章于 2023-03-31 00:52:34 发布