LINQ在编程中的概念 [英] Concept of LINQ in programming

查看:52
本文介绍了LINQ在编程中的概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我对以......格式编写的语法和方法有疑问......<>



Ex:IEnumerable< report>



我的问题是,我们何时何地使用这些类型的语法和什么他们和它的用途是什么?



你能详细说明吗?



HTML编码 - OriginalGriff [/ edit]

解决方案

那个(斜角括号; <> )是通用的,而不是LINQ。它们是两个完全不同的东西。



我可以看到,是什么让你迷惑自己,这是LINQ操作的结果。



 使用 System.Linq; 

// 这是通用的
var aCollection = new List< int> { 1 2 3 ,< span class =code-digit> 4 , 5 };

// 这是LINQ
var result = 来自项目 aCollection
// where(如果需要)
选择 item;
< / int >





Generic用于将类型作为参数传递,而不仅仅是变量或对象。通过传递一个类型,我的意思是,你可以指示编译器,或者创建一个整数或字符串项列表等等。



  var  intList =  new  List< int> { 1  2  3 }; 
var stringList = new List< string> { Hello World};
< / string > < / int >





另一方面,LINQ是C#(和VB.NET)的非常强大功能​​。概念(和查询构建)与SQL非常相似。首先选择数据源,然后对其执行操作以获取集合(或单个项目)。例如,上面的代码。简短的答案摘要不能总结利弊,因此,请阅读下面的指南和文章。



LINQ(语言集成查询) [ ^ ]

System.Collections.Generic Namespace [ ^ ]



CodeProject文章:

查看LINQ [ ^ ]

LINQ to Life [ ^ ]

新手的LINQ常见问题解答 [ ^ ]

Generics< C#> [ ^ ]

C#2.0中的泛型 [ ^ ]


它们不是Linq,它们被称为Generics,它们是一种编写类,接口或方法的方法,它可以处理许多不同的类类型,而无需在设计时为每个可能的类编写代码。使用VS2005在.NET V2.0中引入了泛型,在VS2008中直到V3.0才能使用Ling。



见这里: MSDN:泛型 [ ^ ]因为它太大了解在像这样的小文本框中的任何细节! :笑:

Hi All,

I do have a doubt on the syntax and methods written in a format I......<>

Ex: IEnumerable<report>

My question is, When and where we use these type of syntax and what are they and it's uses?

Can you please elaborate on this?

[edit]HTML encoded - OriginalGriff[/edit]

解决方案

That (angled brackets; <>) is "generic", not LINQ. They are two entirely separate things.

I can see, what made you confuse yourself, the result of a LINQ operation.

using System.Linq;

// This is generic
var aCollection = new List<int> { 1, 2, 3, 4, 5 };

// This is LINQ
var result = from item in aCollection
             // where (if required)
             select item;
</int>



Generic is used to pass a type as a parameter, not just a variable or object. By passing a type, I mean, that you can instruct the compiler, either to create a list of integers or string items and so on.

var intList = new List<int> { 1, 2, 3 };
var stringList = new List<string> { "Hello", "World" };
</string></int>



LINQ on the other hand is a "very powerful" feature of C# (and VB.NET). The concept (and query building) is very much similar to SQL. You first select a data source, then you perform the operations on it to get a collection (or a single item). For example, the code above. A short answer summary cannot sum up the "pros and cons", so, please read the guides and the articles attached below.

LINQ (Language-Integrated Query)[^]
System.Collections.Generic Namespace[^]

CodeProject articles:
A Look at LINQ[^]
LINQ to Life[^]
LINQ FAQ for Newbies[^]
Generics <C#>[^]
Generics in C# 2.0[^]


They are not Linq specifically, they are called Generics and they are a way to write a class, interface, or method which can work with many different class types without having to code for each possible class at design time. Generics were introduced in .NET V2.0 with VS2005, and Ling wasn't available until V3.0 in VS2008.

See here: MSDN: Generics[^] as it's far too big a subject to explain in any detail in a little textbox like this! :laugh:


这篇关于LINQ在编程中的概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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