Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 智力?提高性能_C#_Multidimensional Array_Casting - Fatal编程技术网

C# 智力?提高性能

C# 智力?提高性能,c#,multidimensional-array,casting,C#,Multidimensional Array,Casting,我对编程非常陌生,我想知道将int?转换为int会有什么样的性能损失?我有一个巨大的三维int?数组,有时我不得不向int投下大量。我的性能会受到很大的影响吗?请在Eric Lippert的博客系列中找到答案,该系列介绍了从开始的可空类型 在那里,他将可空结构绘制为 struct Nullable<T> where T : struct { ... public T Value { get { if (!this.HasValue) throw

我对编程非常陌生,我想知道将
int?
转换为
int
会有什么样的性能损失?我有一个巨大的三维
int?
数组,有时我不得不向
int
投下大量。我的性能会受到很大的影响吗?

请在Eric Lippert的博客系列中找到答案,该系列介绍了从开始的可空类型

在那里,他将可空结构绘制为

struct Nullable<T> where T : struct
{
  ...
  public T Value
  {
    get
    {
      if (!this.HasValue) throw something;
      return this.value;
    }
  }
  public T GetValueOrDefault() 
  {
    return this.value; 
  }
  ... 
}
struct可为空,其中T:struct
{
...
公共价值
{
收到
{
如果(!this.HasValue)扔东西;
返回此.value;
}
}
公共T GetValuerDefault()
{
返回此.value;
}
... 
}

所以它只是添加了一个
if(bool)

你能防止插入空int吗?我会受到很大的性能影响吗?这取决于你的代码。最有可能的是,前后的语句花费了两倍的时间。不会有性能损失。请编写代码。买一块秒表。衡量其性能。然后你就会知道它有多快了。没有其他方法可以知道一段代码有多快。我们不知道你写的代码有多快,我们当然也不知道它是否足够快,是否能被你的客户接受。这很简单,我还以为它更复杂。