Is there any performance advantage with the "chaining" in .NET?

When retrieving a search code value from a table, some people do this ...

Dim dtLookupCode As New LookupCodeDataTable()
Dim taLookupCode AS New LookupCodeTableAdapter()
Dim strDescription As String

dtLookupCode = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL")
strDescription = dtLookupCode.Item(0).Meaning

... however, I also saw how “chained” were made in this way ...

strDescription = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL").Item(0).Meaning

... which bypasses the search code data table primarily because the table adapter knows what the structure of its result set looks like.

Does the chaining method save the overhead of creating a data table object, or is it efficiently created anyway to properly handle the .Item (0) .Meaning instruction?

+3
source share
11 answers

"" , , . :

Dim dtLookupCode As New LookupCodeDataTable()
Dim taLookupCode AS New LookupCodeTableAdapter()

VB . :

dtLookupCode = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL")

dtLookupCode , ( ).

, , , , "", . ( , .)

, , - :

Dim taLookupCode AS New LookupCodeTableAdapter
Dim dtLookupCode As LookupCodeDataTable
Dim strDescription As String

dtLookupCode = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL")
strDescription = dtLookupCode.Item(0).Meaning

. , . , - :

Dim taLookupCode AS New LookupCodeTableAdapter
Dim dtLookupCode As LookupCodeDataTable = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL")
Dim strDescription As String = dtLookupCode.Item(0).Meaning
+4

. , . - .

+5

, "inline", - . , , , . , , ?

+2

.

, "inlining" (.. ), , , . , , , , . , , .

. :

if (ConfigurationManager.AppSettings("ConnectionString") == null)
{
    throw new MissingConfigSettingException("ConnectionString");
}

string connectionString = ConfigurationManager.AppSettings("ConnectionString");

:

string connectionString = ConfigurationManager.AppSettings("ConnectionString")

if (connectionString == null)
{
    throw new MissingConfigSettingException("ConnectionString");
}

, AppSettings() AppSettings , :

// Disassembled AppSettings member of ConfigurationManager 

public static NameValueCollection AppSettings
{
    get
    {
        object section = GetSection("appSettings");

        if ((section == null) || !(section is NameValueCollection))
        {
            throw new
                ConfigurationErrorsException(SR.GetString("Config_appsettings_declaration_invalid"));
        }

        return (NameValueCollection) section;
    }
}
+2

, .

, , - .

+1

.

.

: ?

, .

, , , .

. , .

, Item (1) Item (2), , , .

, .

+1

"" Demeter, , LookupCodeDataTable.

​​:

function getMeaning( lookupCode as LookupCodeDataTable)
 getMeaning=lookupCode.Item(0).Meaning
end function

:

strDescription=getMeaning(taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL"))

getMeaning() , LookupCodeDataTable , getMeaning(), .

+1

, .

0

:

dtLookupCode = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL")
strDescription = dtLookupCode.Item(0).Meaning

:

strDescription = taLookupCode.GetDataByCodeAndValue("EmpStatus", "FULL").Item(0).Meaning

.

(dtLookupTable). . . , .

, :

Dim dtLookupCode As New LookupCodeDataTable()

. , LookupCodeDataTable, . VB, , :

Dim dtLookupCode As LookupCodeDataTable

(, ), .

0

, taLookupCode.GetDataByCodeAndValue( "EmpStatus", "FULL" ) Item (0) . , log (n) n, .

0

, : .

, try/catch , .

try/catch, . :

  • , GetDataByCodeAndValue null?
  • , ?

You cannot check these values ​​without try / catch if you are clinging.

0
source

Source: https://habr.com/ru/post/1697234/


All Articles