很简单的一个问题

.Net技术 码拜 8年前 (2016-05-15) 929次浏览
本人写了一个小代码,本人标红的地方 是想输入null,问一下C#可以输入null吗?有这个键吗?还是永远都不可能输入为null?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace delete
{
class Program
{
static void Main(string[] args)
{
double? x = Get();
if (x == null)
Console.WriteLine(“null”);
}
static double? Get()
{
double? re;
string user = Console.ReadLine();
re = double.Parse(user);
return re;
}
}
}
解决方案

6

输入的字符串可以是null
string user=”null”;与string user=null;不同

6

键盘是无法输入null的,你可以设置一个标志,当你输入的是这个标志的时候,就认为是null

8

string user = Console.ReadLine();
if(user==”null”)
user==null;

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明很简单的一个问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)