简体   繁体   English

无法将 MathNet.Numerics.LinearAlgebra.Matrix 定义为 Const?

[英]Unable to define MathNet.Numerics.LinearAlgebra.Matrix as Const?

Here is the C# code :这是 C# 代码:

const MathNet.Numerics.LinearAlgebra.Matrix<Complex32> ket_Zero =
   MathNet.Numerics.LinearAlgebra.Matrix<Complex32>.Build.DenseOfRowMajor(2, 1,
       new MathNet.Numerics.Complex32[] {
           new MathNet.Numerics.Complex32(1,0),
           new MathNet.Numerics.Complex32(0,0)
       } );

It's ok if I don't put the const keyword.如果我不放 const 关键字就可以了。 But if I want to defined this as a constant, Microsoft Visual Studio rejects with但是如果我想将其定义为常量,Microsoft Visual Studio 会拒绝

Error Code CS0133 = The expression being assigned to 'Form1.ket_Zero' must be constant.错误代码 CS0133 = 分配给“Form1.ket_Zero”的表达式必须是常量。

I also tried replacing const with readonly but won't work too.我也尝试用readonly替换const但也不起作用。
How can I define matrices as constants?如何将矩阵定义为常量?

Here is the documentation from MSDN on what can be defined as const.这是MSDN上关于什么可以定义为 const 的文档。 I will quote the required part.我将引用所需的部分。

Only the C# built-in types (excluding System.Object) may be declared as const.只有 C# 内置类型(不包括 System.Object)可以声明为 const。 User-defined types, including classes, structs, and arrays, cannot be const.用户定义的类型,包括类、结构和数组,不能是 const。

In your case, you are trying to define MathNet.Numerics.LinearAlgebra.Matrix<Complex32> as const but it is used declared type therefore can not be const在您的情况下,您试图将MathNet.Numerics.LinearAlgebra.Matrix<Complex32>定义为 const 但它使用声明类型因此不能是const

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 .NET 框架中使用 MathNet.Numerics.LinearAlgebra 进行矩阵连接 - Matrix concatenation using MathNet.Numerics.LinearAlgebra in .NET Framework .Net框架中的MathNet.Numerics.LinearAlgebra - MathNet.Numerics.LinearAlgebra in .Net framework 无法使 MathNet.Numerics.LinearAlgebra 中的 Matrix Method 正确语法工作 - Cannot get correct syntax for Matrix Method in MathNet.Numerics.LinearAlgebra to work MathNet.Numerics.LinearAlgebra:如何快速将Vector附加到另一个Vector? - MathNet.Numerics.LinearAlgebra: how to append a Vector to another quickly? 大型稀疏矩阵计算-MathNet数值 - Large Sparse Matrix Calculation - MathNet Numerics Entity Framework 6 持久化一个 MathNet.Numerics 矩阵 - Entity Framework 6 Persist a MathNet.Numerics Matrix MathNet数值中的Matrix,SparseMatrix和DenseMatrix之间的区别? - Difference between Matrix, SparseMatrix, and DenseMatrix in MathNet Numerics? 使用MathNet.Numerics进行矩阵求逆 - Matrix Inverse using MathNet.Numerics 我可以将 MathNet 数字库中的矩阵更改为数组吗? - Can I change a matrix in MathNet Numerics Library to an array? 方法之间的区别矩阵 <T> 除(双标量)和矩阵 <T> MathNet数值中的DivideByThis(双标量)吗? - Difference between methods Matrix<T> Divide(double scalar) and Matrix<T> DivideByThis(double scalar) in MathNet Numerics?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM