c# 判断是否为空然后赋值的4种实现方法
作者:杨明波(Leo Yang) 时间:2021-06-06 22:01:12
如果一个对象不为空null时,把它赋给另外一个对象:
像下面这个样子,需要把str的值赋给result,前提条件是在不为空null的前提之下:
class Aj
{
public void DemoNUll()
{
string str = null;
string result = "";
}
}
方法一:
if (str == null)
result = "";
else
result = str;
方法二:
if (str != null)
{
result = str;
}
方法三:
result = str == null ? "" : str;
方法四:
result = str ?? "";
来源:http://www.cnblogs.com/insus/p/8004097.html
标签:c#,判断,是否为空,赋值
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
java操作solr实现查询功能的实例
2023-08-04 10:41:34
![](https://img.aspxhome.com/file/2023/0/95940_0s.png)
Android利用AsyncTask异步类实现网页内容放大缩小
2022-11-28 05:34:47
Java实现一个顺序表的完整代码
2023-09-21 01:00:59
![](https://img.aspxhome.com/file/2023/0/62500_0s.png)
C#中分部类和分部方法的应用
2022-08-16 06:49:05
Android编程实现图片的颜色处理功能示例
2022-10-08 23:15:25
![](https://img.aspxhome.com/file/2023/8/92588_0s.gif)
Java-JFrame-swing嵌套浏览器的具体步骤
2022-11-26 19:30:10
C#采用HttpWebRequest实现保持会话上传文件到HTTP的方法
2023-07-18 17:20:29
springboot 自定义启动器的实现
2021-06-05 00:33:14
![](https://img.aspxhome.com/file/2023/7/72567_0s.png)
springboot整合websocket最基础入门使用教程详解
2023-11-30 00:20:24
![](https://img.aspxhome.com/file/2023/6/78036_0s.png)
Maven打包jar包没有主属性问题解决方案
2023-11-25 06:56:32
C#实现FTP传送文件的示例
2022-06-24 01:15:20
SpringBoot中多环境配置和@Profile注解示例详解
2023-11-29 05:39:04
android中使用SharedPreferences进行数据存储的操作方法
2023-06-16 17:37:42
![](https://img.aspxhome.com/file/2023/1/83531_0s.png)
C#设计模式之外观模式介绍
2023-03-15 06:22:31
![](https://img.aspxhome.com/file/2023/5/68645_0s.jpg)
dubbo将异常转换成RuntimeException的原因分析 ExceptionFilter
2023-11-24 14:25:13
![](https://img.aspxhome.com/file/2023/3/64143_0s.jpg)
Java中static关键字的作用和用法详细介绍
2022-07-05 08:33:53
SpringBoot使用GraphQL开发Web API实现方案示例讲解
2023-05-17 16:50:22
![](https://img.aspxhome.com/file/2023/8/85418_0s.png)
Android登录注册功能 数据库SQLite验证
2023-10-01 20:58:55
![](https://img.aspxhome.com/file/2023/6/86926_0s.gif)
Mybatis plus 配置多数据源的实现示例
2023-10-04 15:57:33
![](https://img.aspxhome.com/file/2023/7/96067_0s.png)
使用spring通过aop获取方法参数和参数值
2022-06-04 16:28:33