0

AnswerRecords return a list of DnsRecordBase:

List<DnsRecordBase> _Records = _DnsMessage.AnswerRecords;

MxRecord inherit from DnsRecordBase:

public class MxRecord : DnsRecordBase

How to cast _Records has a list of MxRecord ?

I have tried:

List<MxRecord> _Records = (MxRecord)_DnsMessage.AnswerRecords;
List<MxRecord> _Records = _DnsMessage.AnswerRecords as MxRecord;

This syntaxes doesn't work :)

chridam
  • 95,056
  • 21
  • 214
  • 219
user2705397
  • 61
  • 1
  • 6

1 Answers1

4

This should work if all elements in _Records are MxRecord

List<DnsRecordBase> _Records = _DnsMessage.AnswerRecords;
List<MxRecord> _MxRecords = _Records.Cast<MxRecord>().ToList();
Sriram Sakthivel
  • 69,953
  • 7
  • 104
  • 182