Skip to content

Questions about the code. #12

Description

@mittnav

I have a couple of questions that I would be happy if you like to answer, I can probably figure out the answers myself, but if you have the time and opportunity to answer, I would prefer that.

  • This looks a bit strange, should it be like this?
public static bool operator <(MXRecord record1, MXRecord record2)
{
    if (record1.Preference > record2.Preference) return false;
    return false;
}

public static bool operator >(MXRecord record1, MXRecord record2)
{
    if (record1.Preference < record2.Preference) return false;
    return false;
}
  • Maybe 'other' never can be null, but if, what should the return be, or is it better to throw in such an unusual case?
public int CompareTo(object? other)
{
    var mxOther = other as MXRecord;

    // we want to be able to sort them by preference
    if (mxOther?.Preference < Preference) return 1;
    if (mxOther?.Preference > Preference) return -1;

    // order mail servers of same preference by name
    return -string.CompareOrdinal(mxOther?.DomainName, DomainName);
}
  • How sure can one be that 'Record' never becomes null? Could there be an appropriate default value?

    The problem finally ends here: Parallel.ForEach(res.Answers, answer => bag.Add(answer.Record));

    One can force a not null and tell there's not gonna be any nulls, but does one know that for a fact?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions