Creating a new object using another constructor

EDIT: Sorry if this seems a bit obvious / simple, I tried to find the answer, but I'm not sure how to put it right.

I am learning a bit of C #, and I am having trouble drawing new objects around the created objects, where the constructor and class type are different. Thus, a regular object will be created:

Object obj = new Object();

This is pretty obvious, but since I was studying interfaces, I came across some syntax, for example:

interface ISaveable {
    string Save();
}

public class Catalog : ISaveable {
    string Save() {
        return "Catalog Save";
    }

    string ISaveable.Save(){
        return "ISaveable Save";
    }
}

And then the textbook continued to do something like that:

Catalog c1 = new Catalog();

So, I know that an instance of a new instance of the catalog class is being created, but I can’t understand in life that the following line:

ISaveable c2 = new Catalog();

( ..), c2. (ISaveable) ( ())?

!

+4
2

, ,

Catalog c1 = new Catalog();

ISaveable c2 = new Catalog();

, Catalog ( ), ; Save c1 c2 .

+1

( ..), c2. (ISaveable), ( ())?

ISaveable c2 = ();

:

  • Catalog
  • ISaveable

, Catalog, ISaveable.

0

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


All Articles