AnswerRecords
返回DnsRecordBase
的列表:
List<DnsRecordBase> _Records = _DnsMessage.AnswerRecords;
MxRecord
继承自DnsRecordBase
:
public class MxRecord : DnsRecordBase
如何投标_Records
有一个MxRecord
列表?
我试过了:
List<MxRecord> _Records = (MxRecord)_DnsMessage.AnswerRecords;
List<MxRecord> _Records = _DnsMessage.AnswerRecords as MxRecord;
此语法不起作用:)
答案 0 :(得分:4)
如果_Records
中的所有元素都是MxRecord
List<DnsRecordBase> _Records = _DnsMessage.AnswerRecords;
List<MxRecord> _MxRecords = _Records.Cast<MxRecord>().ToList();