RTI Connext .NET API (legacy)  Version 6.1.1
DDS::Ext::LoanedSamples< T > Class Template Reference

A collection of data samples and sample info. More...

#include <managed_subscription.h>

Inherits IEnumerable< LoanedSample< T > >, and IDisposable.

Properties

System::Int32 Count [get]
 Returns the number of samples. More...
 
LoanedSample< T > default [int] [get]
 Returns a sample by index. More...
 

Detailed Description

template<typename T>
class DDS::Ext::LoanedSamples< T >

A collection of data samples and sample info.

Warning
This class is located in the DDS.Ext namespace in order to avoid name collisions in applications that use Request-Reply, in which RTI.Connext.Infrastructure.LoanedSamples is defined. In a future release, DDS.Ext.LoanedSamples will be moved to the DDS namespace, and will replace RTI.Connext.Infrastructure.LoanedSamples.

LoanedSamples is a loaned collection returned by TypedDataReader::take(), TypedDataReader::read() or TypedDataReader::select(). Each element is a LoanedSample, containing the properties data and info.

This collection implements IDisposable to manage the loan. To return the loan call Dispose() or use a using statement.

This collection also implements IEnumerable. This allows using a LoanedSamples collection in a foreach statement, or in a Linq query.

Examples:

(The following examples assume a reader for the following IDL type)

struct MyType {
string myName;
long myValue;
};

This example prints myValue for all the samples with valid data:

using (var samples = reader.take())
{
foreach (var sample in samples)
{
if (sample.info.valid_data)
{
Console.WriteLine(sample.data.myValue);
}
}
}

This example obtains a list containing the values of the field myValue for those samples with valid data such that myName = "Foo":

using (var samples = reader.take())
{
var values =
(from sample in samples
where sample.info.valid_data && sample.data.myName == "Foo"
select sample.data.myValue).ToList();
}

Property Documentation

◆ Count

template<typename T>
System:: Int32 DDS::Ext::LoanedSamples< T >::Count
get

Returns the number of samples.

◆ default

template<typename T>
LoanedSample< T> DDS::Ext::LoanedSamples< T >::default[int]
get

Returns a sample by index.