如何使用只读属性实例类

| 我想从所有必需的信息中创建
AudioFormat
类的实例。 基本上,我拥有的是
int
BitsPerSample
int
频道
int
样本每秒
WaveFormatType
WaveFormat 问题是,仅仅使用类似
AudioFormat format = new AudioFormat();
format.BitsPerSample = BitsPerSample;
[...]
Property or indexer \'System.Windows.Media.AudioFormat.BitsPerSample\' cannot be assigned to -- it is read only
开始不起作用。 有没有简单的方法来创建这样的对象?如果没有,我应该怎么做呢?使用继承,覆盖属性,使它们具有二传手?创建对象的XML表示然后反序列化?使用其他丑陋的技巧(没有
unsafe
:-))?     
已邀请:
您不应该直接创建此类。 它存在使用内部构造函数从ѭ9属性返回
AudioCaptureDevice
类的信息。 如果您尝试将其用于自己的目的,则应创建自己的类。     

要回复问题请先登录注册