この初心者の質問には申し訳ありませんが、私はC#の非常に新しく、セマンティクスです。C#構造体のオブジェクトフィールドに代入/キャスト
public struct MT5Command{
public MT5CommandType Type{ get; set;}
public AutoResetEvent ThreadWaitHandle { get; set; }
public object InParam { get; set; }
public object OutParam { get; set; }
}
そして、このコードスニペット:私は、次の構造体を持っている
MT5Command Cmd = new MT5Command();
Cmd.Type = MT5CommandType.GetServerInformation;
Cmd.ThreadWaitHandle = waitHandle.Value;
attributes = new ServerAttributes();
Cmd.OutParam = attributes;
....
ServerAttributes SrvAttributes = new ServerAttributes();
Cmd.OutParam = (ServerAttributes)SrvAttributes;
最後の行はコンパイルされません:それはforeachの反復変数 ' 方法であるため、「コマンド」のメンバーを変更することはできません他のServerAttributes構造体にOutParamフィールドを割り当てることは可能ですか?
これがfor-eachループの外である:
foreach (MT5Command Cmd in mCommandQueue.GetConsumingEnumerable())
{
...
}
おかげで、ユルゲン
:詳細については
。しかし基本的に、あなたは 'foreach(barでMT5コマンドfoo){foo.OutParam = ...}'のようなことをしています。代わりにfor-loopを使用してコレクション要素に直接アクセスすることができます。 'bar [i]'。 – ashes999