当前位置:编程学习 > C#/ASP.NET >>

用C#知识怎么做?急。。。。

定义一个类 类名ArrayOperation.类中定义如下静态方法:  
(1) 求双精度浮点型数组的平均值,方法名:ComputeAverage
(2) 求双精度浮点型数组的和,方法名:ComputeSum
(3) 求双精度浮点型数组的最大值,方法名:ComputeMax
(4) 求双精度浮点型数组的最小值,方法名:ComputeMin
(5) 求双精度浮点型数组的排序,方法名:ComputeSort
(6) 最后定义一个Test类,测试这五个方法
--------------------编程问答-------------------- --------------------编程问答-------------------- 楼上彪悍  UP --------------------编程问答-------------------- 楼上正解 --------------------编程问答--------------------
引用 1 楼 caozhy 的回复:
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        ……

坑人啊,老师看见这代码会骂人的 --------------------编程问答--------------------
引用 4 楼 lihanbing 的回复:
引用 1 楼 caozhy 的回复:
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] a……


把静态类放进去就是了撒…… --------------------编程问答-------------------- 我敢保证,老师看到LZ如此熟练的使用lambda,肯定不会骂人。 --------------------编程问答-------------------- 改改就能交了···呵呵 1楼 up···
引用 1 楼 caozhy 的回复:
C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] arg……
--------------------编程问答--------------------
引用 5 楼 saberxl02 的回复:
引用 4 楼 lihanbing 的回复:
引用 1 楼 caozhy 的回复:
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
sta……

从前有个小学一年级老师,给小学生留了4则运算的作业,小学生很聪明,回家拿计算器按出结果,第二天交给老师。。。。。。 --------------------编程问答--------------------
引用 8 楼 lihanbing 的回复:
引用 5 楼 saberxl02 的回复:

引用 4 楼 lihanbing 的回复:
引用 1 楼 caozhy 的回复:
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
……

从前有个小朋友,让他写篇作文,他很懒,找邻居伯伯帮忙,结果老师说这个字像大人的。 --------------------编程问答-------------------- 一起学习。 --------------------编程问答-------------------- 来一个动态方法的。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Test.PreformTest();            
        }
    }

    class ArrayOperation : System.Dynamic.DynamicObject
    {
        public Func<double[], double[]> ComputeSort = x => x.OrderBy(y => y).ToArray();
    
        public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
        {
            MethodInfo[] mis = typeof(Enumerable).GetMethods();
            MethodInfo mi = mis.Where(x => x.Name == binder.Name.Substring(7) && x.ReturnType == typeof(double) && x.ToString().Contains("IEnumerable`1[System.Double]")).First();
            result = mi.Invoke(null, new object[] { (args[0] as double[]).AsEnumerable<double>() });
            return true;
        }

    }

    class Test
    {
        public static void PreformTest()
        {
            double[] array = new double[] { 1.08, 3.5, 5.0, 0.98, -1.1, 4.26, 7.88, 3.6, 1.80 };
            dynamic o = new ArrayOperation();
            Console.WriteLine("数据:");
            array.ToList().ForEach(x => Console.Write(x + "\t"));
            Console.WriteLine("\r\nAverage = {0}, Sum = {1}, Max = {2}, Min = {3}.",
                o.ComputeAverage(array),
                o.ComputeSum(array),
                o.ComputeMax(array),
                o.ComputeMin(array));
            Console.WriteLine("排序:");
            double[] sorted = o.ComputeSort(array);
            sorted.ToList().ForEach(x => Console.Write(x + "\t"));
            Console.WriteLine();
        }
    }
}
--------------------编程问答-------------------- 我敢保证,LZ够胆交,老师就够胆骂! --------------------编程问答-------------------- 很牛逼 --------------------编程问答--------------------
引用 1 楼 caozhy 的回复:
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)……


正解
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,