IDataStore<TModel>.BinarySearch<TValue>(Func<TModel, TValue> searchProperty, TValue propertyValue) Method
.NET Standard 2.x
Searches for the index number of the specified property name and value in the primary buffer. The index number is the same as the zero-based row number in the primary buffer.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
int BinarySearch<TValue>(Func<TModel, TValue> searchProperty, TValue propertyValue);
Parameters
searchProperty
Func<TModel, TValue>
The property name in the model.
propertyValue
TValue
The property value in the model.
Returns
System.Int
Returns the zero-based index of the model object in the primary buffer if found; otherwise, -1.
Remarks
The index number starts from 0 which is consistent with C#.
Examples
The following code example shows how to use the BinarySearch
method to find the index number of a specified property name and value.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStore_GenericExamples
{
public class BinarySearchExample
{
private readonly SchoolContext _context;
public BinarySearchExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Instantiates a DataStore object with datawindow object: d_department.
var datastore = new DataStore<D_Department>(_context);
datastore.Retrieve();
// No record is found.
int index = datastore.BinarySearch(a => a.Name, "Department New");
Console.WriteLine("Not found: {0}", index);
// Finds a record in the datastore whose Name="Engineering"
index = datastore.BinarySearch(a => a.Name, "Engineering");
Console.WriteLine("Found: {0}", index);
/*This code produces the following output:
Not found: -1
Found: 0
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x