Get Length 使用dynamic关键字

http://www.codewars.com/kata/566f571ed78037c7b6000036/train/csharp

You don't have any idea what is the type of the input object, but you know that it has Length property.

(The input can be any type of object that has Length property)

So, the GetLength method should return the Length of input.

public class Kata
{
    public static int GetLength(object obj)
    {
        dynamic a = obj;
        return a.Length;
    }
}

 

你可能感兴趣的:(Get Length 使用dynamic关键字)