What is the basis of all interfaces in .net, as well as the basis for all classes - an object

I would like to pass an interface to the signature of a method that takes Object as its parameter, so I'm curious about this question

public Stream GetViewStream(string viewName, object model, ControllerContext context)
  • instead of an object, I would like to pass the Imodel interface without changing the signature. Is there a base class for interfaces?

  • Also in the new mvc2 is there a way to avoid the controller context altogether?

+3
source share
4 answers

I would answer only the first question: why is there no common base interface for all interfaces?

, , System.Object. .

, . , . , , . , , , , . , , , - ? , , ?

, System.object .Net. , COMMON- .Net , , ex:.ToString()

, , , / .

. IFlyable, Fly() , IFlyable. , Flyable , . .

public void FlyTheObject(IFlyable flyingObject)
{ 
    flyginObject.Fly();
}

, Fly().

, Object, . , . , , , .Net- System.Object, , , .

+3

, . .

( ) - ?

0

, , :

 private IEnumerable<int> myInterfaceVariable = new List<int>();

, , , , .

:

public class InterfaceAsObject
{
    private IEnumerable<int> myInterfaceVariable = new List<int>();

    private void CallDoSomething()
    {
        DoSomething(myInterfaceVariable);
    }

    private void DoSomething(object input)
    {


    }
}
0

Re 1, , , , , , , , IModel , ( !) IModel. "" null.

, - , . (, IDerivedModel : IModel), .

.

0

Source: https://habr.com/ru/post/1758364/


All Articles