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