Filter Rows Example (C#)
[C#]
/* COPYRIGHT(C), SIMPLEXAR SOFTWARE LIMITED, 2006-2008.
* All rights reserved.
*
* Use of this copyright notice is precautionary only, and does not imply
* publication or disclosure. The content of this work contains confidential
* and proprietary information of Simplexar Software Limited. Any duplication,
* modification, distribution, or disclosure in any form, in whole, or in part,
* is strictly prohibited without express prior written permission.
*/
// Get namespaces.
using System;
using Simplexar.Statsar;
// Start namespace.
namespace Simplexar.Examples.Statsar
{
/// <summary>
/// This example uses expressions to filter out unwanted rows from
/// a data sheet. This method does not alter the data sheet. Instead
/// a new data sheet with filtered rows is returned.
/// </summary>
public static class Example
{
/// <summary>
/// The application entry point.
/// </summary>
public static void Main()
{
try
{
RunExample();
}
catch(Exception exception)
{
Console.WriteLine(exception);
}
Console.WriteLine("Press ENTER to terminate.");
Console.ReadLine();
}
private static void RunExample()
{
// Create a calculator.
StatsCalculator calculator = new StatsCalculator();
// Use the calculator to load the sheet.
DataSheet sheet = calculator.Load(
@"..\..\..\..\..\Data\Salaries.csv");
Console.WriteLine(sheet);
// Suppose we wish to filter this data to include only states
// with a salary of at least $60,000 or above. The expression
// we can use is: "Salary >= 60".
DataSheet filterSheet1 = sheet.Filter("Salary >= 60");
Console.WriteLine(filterSheet1);
// As a second example, suppose that instead of salaries of at
// least $60,000 we wanted to find out which states have a salary
// of between $45,000 and $55,000 inclusive. We could use the
// following expression to do this: "Salary >= 45 AND Salary <= 55"
// However, the expression syntax also supports the BETWEEN
// keyword, meaning that we can also use the following more
// readable expression: "Salary BETWEEN 45 AND 55".
DataSheet filterSheet2 = sheet.Filter("Salary BETWEEN 45 AND 55");
Console.WriteLine(filterSheet2);
}
}
}