From 7e79872115ea684ccf170b31d55e8fa760a2ccd1 Mon Sep 17 00:00:00 2001 From: sunnypaine Date: Thu, 13 Jul 2023 02:02:55 +0000 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E8=84=91=E5=A3=B3=E7=9A=84=E9=9D=9E?= =?UTF-8?q?=E7=A9=BA=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunnypaine --- c#/NullPointExceptionValidate | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 c#/NullPointExceptionValidate diff --git a/c#/NullPointExceptionValidate b/c#/NullPointExceptionValidate new file mode 100644 index 0000000..758542a --- /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; + } + } +} -- Gitee