码迷,mamicode.com
首页 > 其他好文 > 详细

Get Length 使用dynamic关键字

时间:2016-05-17 19:10:32      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:

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关键字

标签:

原文地址:http://www.cnblogs.com/chucklu/p/5502590.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!