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
  • 100,957
  • 23
  • 236
  • 235
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
  • 72,067
  • 7
  • 111
  • 189