diff --git a/c#/NullPointExceptionValidate b/c#/NullPointExceptionValidate new file mode 100644 index 0000000000000000000000000000000000000000..758542a7dead8e5fb8f2f4fb7b93cb2ab5f133f6 --- /dev/null +++ b/c#/NullPointExceptionValidate @@ -0,0 +1,39 @@ +using System; + +namespace TestEnum +{ + internal class Program + { + //这段代码是从项目中提取出来的,来自于团队中一个西南交大的女硕士之手 + //这位女硕士队友喜欢怼天怼地对空气,经常写一些价值千万的代码 + + static void Main(string[] args) + { + UserBusiness userBusiness = new UserBusiness(); + User user = userBusiness.GetUserById(1); + if (user == null)//嗯,非空判断,挺有心的 + { + //咦?TMD,有非空判断的心,没有非空判断的脑,你这价值千万的代码,合着你判断了个寂寞啊? + //写代码前,请确保脑子和手是连上了的 + Console.WriteLine($"用户名为{user.Name}的用户不存在。"); + } + } + } + + class User + { + private int Id { get; set; } + public string Name { get; set; } + public string Password { get; set; } + public string Email { get; set; } + } + + class UserBusiness + { + public User GetUserById (int id) + { + User user=null;//从数据库取数据 + return user; + } + } +}