如题

解决方案 »

  1.   

             //Array.Copy检验的条件是,如果源和目标数组的元素类型是内置的值类型,只要能做宽转换(widening conversion)那就可以成功复制。(byte是1字节的,int是4字节的。)
    //代码 如下 //byte数组转int数组
                byte[] source = { 1, 2, 3 };
                int[] intArray = new int[source.Length];
                Array.Copy(source, intArray, source.Length);
    //测试代码
               // foreach (var item in intArray)
               // {
               //     label1.Text += item + "\n";
               // }
      

  2.   

    小字节向大字节的数字co,连强cast都不用
      

  3.   

      public static class AExtension
        {
            public static int Count(this ICountable o)
            {
                return 0;//TODO:
            }
        }
        public interface ICountable
        {
            
        }
    既然你要每个属性统计count,那么每个属性必然也是可以统计count的。
    你可以用扩展函数的方式,每个属性的类都是继承某个可以统计count的接口的,例如ICountable
    然后写相应的扩展函数。扩展函数和类内部的函数调用方式是一样的,当然仅支持.net 3.5以上版本