C#:匿名方法VS命名的方法 [英] C#: Anonymous method vs Named method

查看:127
本文介绍了C#:匿名方法VS命名的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的SO和编程和学习天天有位和高科技件(C#)行话。

I'm new to SO and programming and learning day by day with bits and pieces of tech (C#) jargons.

谷歌搜索了一会儿后,下面是我研究过关于方法

After Googling for a while, below is what I've researched about methods


  1. 一个方法是块语句,服务于代码重用
    &放大器;它也支持不同的签名....超载为前:
    drawShape(2分),drawShape(3pts)等等...

  1. A Method is a block of statements, which serves for code reusability & it also supports overloading with different SIGNATURE....for ex: drawShape(2pts), drawShape(3pts) etc...

这是匿名办法是一家具有语句块,但没有
的名字......(作为其过早问,在重量情况下,我们遇到
匿名方法......任何物品,样品...)

An Anonymous method is one with block of statements, but no name....(as its premature to ask, in wt situation we come across anonymous method...any articles, samples ...)

命名的方法:这里的<一个HREF =htt​​p://msdn.microsoft.com/en-us/library/ms173114.aspx相对=nofollow>一个链接但最终我没有得到什么命名的方法实际上是。 ..

Named method: Here's a link but at the end i didn't get what Named Method actually is...

谁能解释命名的方法是什么,在哪里我们使用匿名方法?

Can anyone explain what a "Named" method is, and where do we use anonymous method?

推荐答案

一个命名方法是,你可以通过它的名字叫(例如,它是有一个名字的函数)的方法。例如,您已经定义了一个函数来添加两个数字:

A named method is a method you can call by its name (e.g. it is a function that has a name). For example, you have defined a function to add two numbers:

int f(int x, int y)
{
    return x+y;
}

您会被它的名字,像这样调用这个方法> F(1,2);

You would call this method by its name like so: f(1, 2);.

匿名方法是作为参数传递给函数,而不需要方法的。名称。这些方法可以在运行时建造或评价从 lambda表达式在编译时。

Anonymous method is a method that is passed as an argument to a function without the need for its name. These methods can be constructed at runtime or evaluated from a lambda expression at compile time.

这些方法在 LINQ查询经常使用例如:

These methods are often used in LINQ queries, for example:

int maxSmallerThan10 = array.Where(x => x < 10).Max();



表达式 X => X - LT; 10 被称为lambda表达式其结果是,将由方法其中,

The expression x => x < 10 is called a lambda expression and its result is an anonymous function that will be run by the method Where.

如果你是一个初学者,我建议你先阅读更多基本的东西。请查看以下链接:

If you are a beginner, I would suggest you first read about more basic stuff. Check out the following links:

  • http://www.completecsharptutorial.com/
  • http://www.csharp-station.com/tutorial.aspx
  • http://www.homeandlearn.co.uk/csharp/csharp.html

这篇关于C#:匿名方法VS命名的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆