I have a class called AlertDialogViewModel
with two constructors, one taking an Object
and a string
and another taking two string
s.
public class AlertDialogViewModel
{
public AlertDialogViewModel(object contentObject, string title)
{
this.ContentObject = contentObject;
this.Title = title;
}
public AlertDialogViewModel(string contentString, string title)
{
this.ContentString = contentString;
this.Title = title;
}
public object ContentObject { get; set; }
public string ContentString { get; set; }
public string Title { get; set; }
}
In a unit test, I create a new instance with the first parameter being null.
[TestMethod]
public void Instancing_string_alert_with_null_content_throws_exception()
{
// Arrange
const string title = "Unit Test";
// Act
var alertDialog = new AlertDialogViewModel(null, title);
}
When I run the unit test, it uses the constructor that takes a string as a first parameter. What is the compiler/runtime doing to determine that is the correct constructor that needs to be used?
This isn't causing any issues with my code, I am just wanting to understand why that constructor is selected in the event that in the future this actually does matter.