1.数据集基类
代码如下 | 复制代码 |
/// <summary> /// 数据集基类 /// </summary> /// <typeparam name="T"></typeparam> public abstract class BaseTB<T> where T : class { private static string _TextFile = Path.Combine(ConfigurationManager.AppSettings["TextDBDir"], typeof(T).Name + "TB.txt"); private static List<T> _data = null; /// <summary> /// <summary> /// <summary> /// <summary> T item = Get(obj); return result; /// <summary> T item = Get(obj); return result; /// <summary> T item = Get(obj); return result; /// <summary> |
2.实体及数据集类
代码如下 | 复制代码 |
/// <summary> /// 实体类 /// </summary> public class User { public string Usn { get; set; } public string Pwd { get; set; } } /// <summary> /// <summary> /// <summary> #endregion /// <summary> foreach (User item in Container) return result; /// <summary> |
3.数据库类
代码如下 | 复制代码 |
/// <summary> /// 数据库 /// </summary> public static class Database { /// <summary> /// 初始化 /// </summary> static Database() { if (!Directory.Exists(ConfigurationManager.AppSettings["TextDBDir"])) { Directory.CreateDirectory(ConfigurationManager.AppSettings["TextDBDir"]); } } private static UserTB _usertb; |
调用示例
代码如下 | 复制代码 |
User user = new User() { Usn = "dnawo", Pwd = "666666" }; Database.UserTB.Add(user); user.Pwd = "999999"; Database.UserTB.Update(user); |
这样在txt文件中是存储按行以tab分开的数据存储格式了,所以这样也方便它来查找数据了哦。