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

wl0502 2011-06-22 10:48:26
定义一个类 类名ArrayOperation.类中定义如下静态方法:
(1) 求双精度浮点型数组的平均值,方法名:ComputeAverage
(2) 求双精度浮点型数组的和,方法名:ComputeSum
(3) 求双精度浮点型数组的最大值,方法名:ComputeMax
(4) 求双精度浮点型数组的最小值,方法名:ComputeMin
(5) 求双精度浮点型数组的排序,方法名:ComputeSort
(6) 最后定义一个Test类,测试这五个方法
...全文
181 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
老鼠爱上猫 2011-06-25
  • 打赏
  • 举报
回复
[Quote=引用 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)……
[/Quote]

正解
crazy_fishegg 2011-06-22
  • 打赏
  • 举报
回复
我敢保证,LZ够胆交,老师就够胆骂!
threenewbee 2011-06-22
  • 打赏
  • 举报
回复
来一个动态方法的。
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();
}
}
}
蓝天云空 2011-06-22
  • 打赏
  • 举报
回复
一起学习。
threenewbee 2011-06-22
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 lihanbing 的回复:]
引用 5 楼 saberxl02 的回复:

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

namespace ConsoleApplication1
……
[/Quote]
从前有个小朋友,让他写篇作文,他很懒,找邻居伯伯帮忙,结果老师说这个字像大人的。
lihanbing 2011-06-22
  • 打赏
  • 举报
回复
[Quote=引用 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……
[/Quote]
从前有个小学一年级老师,给小学生留了4则运算的作业,小学生很聪明,回家拿计算器按出结果,第二天交给老师。。。。。。
woshiliourun 2011-06-22
  • 打赏
  • 举报
回复
改改就能交了···呵呵 1楼 up···
[Quote=引用 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……
[/Quote]
yang1216 2011-06-22
  • 打赏
  • 举报
回复
我敢保证,老师看到LZ如此熟练的使用lambda,肯定不会骂人。
saberxl02 2011-06-22
  • 打赏
  • 举报
回复
[Quote=引用 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……
[/Quote]

把静态类放进去就是了撒……
lihanbing 2011-06-22
  • 打赏
  • 举报
回复
[Quote=引用 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)
……
[/Quote]
坑人啊,老师看见这代码会骂人的
xzf_fancy 2011-06-22
  • 打赏
  • 举报
回复
楼上正解
ningfeihu 2011-06-22
  • 打赏
  • 举报
回复
楼上彪悍 UP
threenewbee 2011-06-22
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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

class ArrayOperation
{
public static Func<double[], double> ComputeAverage = x => x.Average();
public static Func<double[], double> ComputeSum = x => x.Sum();
public static Func<double[], double> ComputeMax = x => x.Max();
public static Func<double[], double> ComputeMin = x => x.Min();
public static Func<double[], double[]> ComputeSort = x => x.OrderBy(y => y).ToArray();
}

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 };
Console.WriteLine("数据:");
array.ToList().ForEach(x => Console.Write(x + "\t"));
Console.WriteLine("\r\nAverage = {0}, Sum = {1}, Max = {2}, Min = {3}.",
ArrayOperation.ComputeAverage(array),
ArrayOperation.ComputeSum(array),
ArrayOperation.ComputeMax(array),
ArrayOperation.ComputeMin(array));
Console.WriteLine("排序:");
ArrayOperation.ComputeSort(array).ToList().ForEach(x => Console.Write(x + "\t"));
Console.WriteLine();
}
}
}
hnxn_zq 2011-06-22
  • 打赏
  • 举报
回复
很牛逼

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧