F-ES Sitecore is right...but also wrong, a little.
You can't use this code:
public void CreateUser(Detail user){
TestClass1 = user as TestClass1;
Console.Write(user.Name + " " + user.Age + " "+ user.TestClass1Property);
}
Because TestClass1Property is not a member of the Detail Interface, and since the object you pass in must be a member of Detail, but doesn't have to be a member of TestClass1, you can't access any TestClass1 specific fields, properties, event, or methods via the
user
variable. And you will get a compilation error if you try.
What you would need to do is:
public interface IDetail
{
string Name { get; set; }
int Age { get; set; }
}
public class TestClass1 : IDetail
{
public int TestClass1Property { get; set; }
}
...
public void CreateUser(IDetail user)
{
TestClass1 tc = user as TestClass1;
if (tc != null)
{
Console.Write(user.Name + " " + user.Age + " " + tc.TestClass1Property);
}
}
Or
...
Console.Write(tc.Name + " " + tc.Age + " " + tc.TestClass1Property);
...