LINQ命名标准 - LAMBDA前pression标准、LINQ、pression、LAMBDA

2023-09-04 10:36:35 作者:梦里梦见醒不来的梦*

我们通常遵循的编码/命名标准为所有的C#语法。举例来说,如果我们声明字符串的方法中,我们使用范围,数据类型,字段名的格式。 (lstrPersonName)

 名单,其中,人物> icolPerson;
私人LoadPersonName()
{
   串lstrPersonaName;
}
 

我是那种想我们如何按照LAMBDA防爆pression的命名标准。尤其是当我们定义的FUNC代表的论点,我们使用短名字如x。例如:

  VAR lobjPerson = icolPerson.Where(X => x.person_id = 100)
 
LINQ体验 4 LINQ简介和LINQ to SQL语句之Where

如果你看一下上面的线,X不遵循任何标准。我也读到了拉姆达EX pression一个目的是减少lenghthy code。

我在这里寻求帮助,以获得正确的方法为命名标准。

  VAR lobjPerson = icolPerson.Where(X => x.person_id = 100)
 

  VAR lobjPerson = icolPerson.Where(lobjPerson => lobjPerson .person_id = 100)
 

解决方案

我已经做了很多节目在VBScript(ASP),并有使用匈牙利命名法来跟踪的数据类型是至关重要的,以保持清醒。在一个类型安全的语言,如C#我觉得没有用都用匈牙利命名法的方式。

描述性的变量名确实非常多的的code的可读性,但它并不总是要描述一个变量的每一个方面。如 A的名字表明它是人的对象的集合,无论它是一个名单,其中,人物> 的IEnumerable<人> 通常并不重要,了解一下code是干什么的,编译器马上告诉你,如果你试图做一些完全错误的。

我经常使用单字母的变量名,其中变量的范围是非常有限的。例如,在一个小循环我标变量,或在lambda EX pressions。

We normally follow coding / naming standard for all C# syntax. For Example, if we declare string inside the method, we use Scope-datatype-FieldName format. (lstrPersonName)

List<Person> icolPerson;
private LoadPersonName()
{
   string lstrPersonaName;
}

i am kind of thinking how do we follow the naming standard in Lambda Expression. Especially when we defined the arguments for func delegate, we use shorted names like x. For Example

var lobjPerson = icolPerson.Where(x => x.person_id = 100)

if you look at the above line, X does not follow any standard. i also read that one purpose of lambda expression is to reduce the lenghthy code.

i am here to seek help to get the right approach for naming standard.

var lobjPerson = icolPerson.Where(x => x.person_id = 100)

OR

var lobjPerson = icolPerson.Where(lobjPerson => lobjPerson .person_id = 100)

解决方案

I've done a lot of programming in VBScript (ASP), and there the use of hungarian notation to keep track of the data type was crucial to keep sane. In a type safe language like C# I find no use at all to use hungarian notation that way.

Descriptive variable names does very much for the readability of the code, but it doesn't always have to describe every aspect of a variable. A name like persons indicates that it's a collection of person objects, whether it's a List<Person> or IEnumerable<Person> is usually not that important to understand what the code is doing, and the compiler tells you immediately if you are trying to do something completely wrong.

I frequently use single letter variable names, where the scope of the variable is very limited. For example the i index variable in a small loop, or in lambda expressions.