Use the. NET Indexer)

Source: Internet
Author: User
Due to inertia, indexer is often used as an entry to feedback results by number.
But like where in SQL, we can actually do a lot.

Using System;
Using System. Collections. Generic;
Using System. text;

Namespace Leleapplication2
{
Class C
{
Float [] Temps =   New   Float [ 10 ] {
56.2f , 56.7f , 56.5f , 56.9f , 58.8f , 61.3f , 65.9f , 62.1f , 59.2f , 57.5f };

Public   Float   This [ Int Index]
{
Get { Return Temps [Index];}
Set {Temps [Index] = Value ;}
}

Public String This[StringIndex]
{
Get{ReturnIndex ;}
}

///   <Summary>
/// Offers features similar to federated PK
///   </Summary>
///   <Param name = "Index"> </param>
///   <Param name = "I"> </param>
///   <Returns> </returns>
Public   String   This [ String Index, Int I]
{
Get { Return Index + I ;}
}

///   <Summary>
/// It can be very similar to the WHERE clause in SQL statements.
///   </Summary>
///   <Param name = "Predicate"> </param>
///   <Returns> </returns>
Public   Float   This [Predicate < Float > Predicate]
{
Get
{
Float [] Matches = Array. findall < Float > (Temps, predicate );

# Region Output intermediate results
String [] Info = Array. convertall < Float , String > (
Matches,
Delegate ( Float F)
{
Return Convert. tostring (f );
}
);
Console. writeline ( String . Join ( " , " , Info ));
# Endregion

ReturnMatches [0];
}
}

///   <Summary>
/// It can be very similar to the effect of a group of where clauses in SQL statements.
///   </Summary>
///   <Param name = "predicates"> </param>
///   <Returns> </returns>
Public   Float   This [ Params Predicate < Float > [] Predicates]
{
Get
{
// For specific implementation, refer to the above example. Basically, it is similar to where for SQL writing.
// The specific implementation is omitted
Return   - 1 ;
}
}

}

Class Program
{
Static   Void Main ( String [] ARGs)
{
C =   New C ();
Console. writeline (C [ 4 ]);
Console. writeline (C [ " Second " ]);
Console. writeline (C [ " Second " , 2 ]);
Console. writeline (
C [
Delegate ( Float F)
{
Return F > 62f;
}]);
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.