Purpose of the IDictionary interface

What the IDictionary interface needs. How can I initialize the IDictionary interface. After all, this is just an interface. The following code snippet is from msdn. I could not understand this.

IDictionary<string, string> openWith = new Dictionary<string, string>();
+3
source share
5 answers

It defines the important functions that a dictionary should implement.

A line from MSDN means that you are creating an openWith object that implements the functions (methods) defined in the IDictionary interface .

When you use a dictionary to declare a variable:

Dictionary<string,string> openWith=.....;

You are communicating with a particular type of object. But when you use

IDictionary<string,string> openWith=....;

, IDictionary, , :)

+11

, ... , ( "" ), , .

" IDictionary", . , , - , IDictionary<T, V>. , , " ".

IDictionary . , IDataReader. ADO.NET, :

public Foo PopulateFromDataReader(SqlDataReader dataReader)

SqlDataReader, , , Access Oracle MySQL Firebird - . , .

:

public Foo PopulateFromDataReader(IDataReader dataReader)

, IDataReader, , , , ADO.NET.

+9

. :

interface IThermometer
{
    double CurrentTemperature { get; }
}

, , . :

class MercuryThermometer : IThermometer
{
    public double CurrentTemperature
    {
        get { return ... /* gets the temperature somehow */ }
    }
}

, .

+5

, , IDictionary<,> (), (), Dictionary<,> ( no I; ).

+1

. unit test , IDictionary . ( ), ( ..).

+1

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


All Articles