int leftDigits = Ops.GetLargestIntegralDigitPosition( left );
int rightDigits = Ops.GetLargestIntegralDigitPosition( right );
int maxResultDigits = 1 + Math.Max( leftDigits, rightDigits );
bool addGuaranteedSuccessful = maxResultDigits < Ops.GetLargestIntegralDigitPosition( Ops.MaxValue );
[Stream] 'A', [Buffer] 'B', [0] 'C', [1] 'D', [2] 'E', [3] 'F', [0-1] 'G', [0-2] 'H', [0-3] 'I', [1-2] 'J', [1-3] 'K', [2-3] 'L'
if(index < 0 || index > array.Length)
{
throw ExceptionBuilder.ArgumentOutOfRange("index", index, 0, array.Length);
}
public static void ArrayIndexInRange(string name, int index, Array array)
{
if(index < 0 || index > array.Length)
{
throw ExceptionBuilder.ArgumentOutOfRange(name, index, 0, array.Length);
}
}
This reduces the code in each method to
index.GuardParam("index")
.ArrayIndexInRange(array);
index.GuardParam("index")
.ArrayIndexInRange(array)
.Satisfies(index % 2 == 0, "The value of index is not even");
public static Guard<int> IsEven(this Guard<int> guard)
{
return guard.Satisfies(guard.Value % 2 == 0, "The value of {0} is not even.", guard.Name);
}
...
index.GuardParam("index")
.ArrayIndexInRange(array)
.IsEven();
[Pure] private int Multiply(int x, int y) { return x * y; }
public void Foo() {
const int a = 2, b = 2;
Multiply(a, b); // Waring: Return value of pure method is not used
}
[StringFormatMethod("message")]
public void ShowError(string message, params object[] args) { /* do something */ }
public void Foo() {
ShowError("Failed: {0}"); // Warning: Non-existing argument in format string
}
Function Definition Table syntax:
[ContractAnnotation("=> halt")]
public void TerminationMethod()
[ContractAnnotation("halt <= condition: false")]
public void Assert(bool condition, string text) // regular assertion method
[ContractAnnotation("s:null => true")]
public bool IsNullOrEmpty(string s) // string.IsNullOrEmpty()
// A method that returns null if the parameter is null, and not null if the parameter is not null
[ContractAnnotation("null => null; notnull => notnull")]
public object Transform(object data)
[ContractAnnotation("s:null=>false; =>true,result:notnull; =>false, result:null")]
public bool TryParse(string s, out Person result)
[CanBeNull] public object Test() { return null; }
public void UseTest() {
var p = Test();
var s = p.ToString(); // Warning: Possible 'System.NullReferenceException'
}
[NotNull] public object Foo() {
return null; // Warning: Possible 'null' assignment
}
Private Sub DisplayWaveform(Of TData)(ByVal waveform As AnalogWaveform(Of TData))
For Each sample As AnalogWaveformSample(Of TData) In waveform.Samples
Debug.WriteLine(String.Format("{0}", sample.Value))
Next
End Sub
private void DisplayWaveform<TData>(AnalogWaveform<TData> waveform)
{
foreach (AnalogWaveformSample<TData> sample in waveform.Samples)
{
Debug.WriteLine(String.Format("{0}", sample.Value));
}
}
Dim buffer As NationalInstruments.DataInfrastructure.Buffer(Of Double) = analogWaveform.GetBuffer(True)
For i As Integer = 0 To (buffer.Size - 1)
'Access data samples using an indexer property to write sample values to an output window.
Debug.WriteLine(buffer(i))
Next
NationalInstruments.DataInfrastructure.Buffer<double> buffer = analogWaveform.GetBuffer(true);
for (int i = 0; i < buffer.Size; i++)
{
// Access data samples using an indexer property to write sample values to an output window.
Debug.WriteLine(buffer[i]);
}
Dim r As New Random()
Dim writableBuffer As NationalInstruments.DataInfrastructure.WritableBuffer(Of Double) = analogWaveform.GetWritableBuffer()
For i As Integer = 0 To writableBuffer.Size - 1
'Add a random value.
writableBuffer(i) += r.NextDouble()
Next
Random r = new Random();
NationalInstruments.DataInfrastructure.WritableBuffer<double> writableBuffer = analogWaveform.GetWritableBuffer();
for (int i = 0; i < writableBuffer.Size; i++)
{
// Add a random value.
writableBuffer[i] += r.NextDouble();
}
Dim dateTimeBuffer As NationalInstruments.DataInfrastructure.Buffer(Of DateTime) = analogWaveform.GetTimeStampBuffer()
For i As Integer = 0 To dateTimeBuffer.Size - 1
'Access buffer samples using an indexer property and write the timestamp to output window.
Debug.WriteLine(dateTimeBuffer(i))
Next
NationalInstruments.DataInfrastructure.Buffer<DateTime> dateTimeBuffer= analogWaveform.GetTimeStampBuffer();
for (int i = 0; i < dateTimeBuffer.Size; i++)
{
// Access buffer samples using an indexer property and write the timestamp to output window.
Debug.WriteLine(dateTimeBuffer[i]);
}
Dim precisionDateTimeBuffer As NationalInstruments.DataInfrastructure.Buffer(Of PrecisionDateTime) = analogWaveform.GetPrecisionTimeStampBuffer()
For i As Integer = 0 To precisionDateTimeBuffer.Size - 1
'Access buffer samples using an indexer property and write the precision time stamp to an output window.
Debug.WriteLine(precisionDateTimeBuffer(i))
Next
NationalInstruments.DataInfrastructure.Buffer<PrecisionDateTime> precisionDateTimeBuffer = analogWaveform.GetPrecisionTimeStampBuffer();
for (int i = 0; i < precisionDateTimeBuffer.Size; i++)
{
// Access buffer samples using an indexer property and write the precision time stamp to an output window.
Debug.WriteLine(precisionDateTimeBuffer[i]);
}
Private Function ConvertData(ByVal values As ComplexInt16()) As ComplexDouble()
Dim convertedValues As ComplexDouble() = Nothing
If DataConverter.CanConvert(values, GetType(ComplexDouble())) Then
convertedValues = CType(DataConverter.Convert(values, GetType(ComplexDouble())), ComplexDouble())
End If
Return convertedValues
End Function
private ComplexDouble[] ConvertData(ComplexInt16[] values)
{
ComplexDouble[] convertedValues = null;
if (DataConverter.CanConvert(values, typeof(ComplexDouble[])))
convertedValues = (ComplexDouble[])DataConverter.Convert(values, typeof(ComplexDouble[]));
return convertedValues;
}
Private Sub DisplayWaveform(Of TData)(ByVal waveform As ComplexWaveform(Of TData))
For Each sample As ComplexWaveformSample(Of TData) In waveform.Samples
Console.WriteLine(String.Format("{0}", sample.Value))
Next
End Sub
private void DisplayWaveform<TData>(ComplexWaveformSample<TData> waveform)
{
foreach (ComplexWaveformSample<TData> sample in waveform.Samples)
{
Console.WriteLine(String.Format("{0}", sample.Value));
}
}
Dim buffer As NationalInstruments.DataInfrastructure.Buffer(Of ComplexDouble) = complexWaveform.GetBuffer(True)
For i As Integer = 0 To buffer.Size - 1
'Access data samples using indexer property and write the data value to an output window.
Debug.WriteLine(buffer(i))
Next
NationalInstruments.DataInfrastructure.Buffer<ComplexDouble> buffer = complexWaveform.GetBuffer(true);
for (int i = 0; i < buffer.Size; i++)
{
//Access data samples using indexer property and write the data value to an output window.
Debug.WriteLine(buffer[i]);
}
Dim r As New Random()
Dim writableBuffer As NationalInstruments.DataInfrastructure.WritableBuffer(Of ComplexDouble) = complexWaveform.GetWritableBuffer()
For i As Integer = 0 To writableBuffer.Size - 1
'Add a random value.
writableBuffer(i) = writableBuffer(i) + New ComplexDouble(r.NextDouble(), r.NextDouble())
Next
Random r = new Random();
NationalInstruments.DataInfrastructure.WritableBuffer<ComplexDouble> writableBuffer = complexWaveform.GetWritableBuffer();
for (int i = 0; i < writableBuffer.Size; i++)
{
//Add a random value.
writableBuffer[i] = writableBuffer[i] + new ComplexDouble(r.NextDouble(), r.NextDouble());
}
Dim precisionDateTimeBuffer As NationalInstruments.DataInfrastructure.Buffer(Of PrecisionDateTime) = complexWaveform.GetPrecisionTimeStampBuffer()
For i As Integer = 0 To precisionDateTimeBuffer.Size - 1
'Access data samples using an indexer property and write the timestamp to an output window.
Debug.WriteLine(precisionDateTimeBuffer(i))
Next
NationalInstruments.DataInfrastructure.Buffer<PrecisionDateTime> precisionDateTimeBuffer = complexWaveform.GetPrecisionTimeStampBuffer();
for (int i = 0; i < precisionDateTimeBuffer.Size; i++)
{
//Access data samples using an indexer property and write the timestamp to an output window.
Debug.WriteLine(precisionDateTimeBuffer[i]);
}
Private Function ConvertData(ByVal values As Integer()) As Double()
Dim convertedValues As Double() = Nothing
If DataConverter.CanConvert(values, GetType(Double())) Then
convertedValues = CType(DataConverter.Convert(values, GetType(Double())), Double())
End If
Return convertedValues
End Function
private double[] ConvertData(int[] values)
{
double[] convertedValues = null;
if (DataConverter.CanConvert(values, typeof(double[])))
convertedValues = (double[])DataConverter.Convert(values, typeof(double[]));
return convertedValues;
}
Private Function ConvertData(ByVal values As Integer()) As Double()
Dim convertedValues As Double() = Nothing
If DataConverter.CanConvert(values, GetType(Double())) Then
convertedValues = CType(DataConverter.Convert(values, GetType(Double())), Double())
End If
Return convertedValues
End Function
private double[] ConvertData(int[] values)
{
double[] convertedValues = null;
if (DataConverter.CanConvert(values, typeof(double[])))
convertedValues = (double[])DataConverter.Convert(values, typeof(double[]));
return convertedValues;
}
Private Function ConvertData(ByVal values As Integer()) As Double()
Dim convertedValues As Double() = Nothing
If DataConverter.CanConvert(Of Double())(values) Then
convertedValues = DataConverter.Convert(Of Double())(values)
End If
Return convertedValues
End Function
private double[] ConvertData(int[] values)
{
double[] convertedValues = null;
if (DataConverter.CanConvert<double[]>(values))
convertedValues = DataConverter.Convert<double[]>(values);
return convertedValues;
}
Private Function ConvertData(ByVal values As Integer()) As Double()
Dim convertedValues As Double() = Nothing
If DataConverter.CanConvert(values, GetType(Double())) Then
convertedValues = CType(DataConverter.Convert(values, GetType(Double())), Double())
End If
Return convertedValues
End Function
private double[] ConvertData(int[] values)
{
double[] convertedValues = null;
if (DataConverter.CanConvert(values, typeof(double[])))
convertedValues = (double[])DataConverter.Convert(values, typeof(double[]));
return convertedValues;
}
Private Function ConvertData(ByVal values As Integer()) As Double()
Dim convertedValues As Double() = Nothing
If DataConverter.CanConvert(Of Double())(values) Then
convertedValues = DataConverter.Convert(Of Double())(values)
End If
Return convertedValues
End Function
private double[] ConvertData(int[] values)
{
double[] convertedValues = null;
if (DataConverter.CanConvert<double[]>(values))
convertedValues = DataConverter.Convert<double[]>(values);
return convertedValues;
}
Private Function ConvertData(ByVal sourceDateTime As DateTime) As Double
Dim convertedValue As Double = 0
If DataConverter.CanConvert(Of Double)(sourceDateTime) Then
convertedValue = DataConverter.Convert(Of Double)(sourceDateTime)
End If
Return convertedValue
End Function
private double ConvertData(DateTime sourceDateTime)
{
double convertedValue = 0;
if (DataConverter.CanConvert<double>(sourceDateTime))
convertedValue = DataConverter.Convert<double>(sourceDateTime);
return convertedValue;
}
Private Function ConvertData(ByVal sourcePrecisionDateTime As PrecisionDateTime) As Double
Dim convertedValue As Double = 0
If DataConverter.CanConvert(Of Double)(sourcePrecisionDateTime) Then
convertedValue = DataConverter.Convert(Of Double)(sourcePrecisionDateTime)
End If
Return convertedValue
End Function
private double ConvertData(PrecisionDateTime sourcePrecisionDateTime)
{
double convertedValue = 0;
if (DataConverter.CanConvert<double>(sourcePrecisionDateTime))
convertedValue = DataConverter.Convert<double>(sourcePrecisionDateTime);
return convertedValue;
}
Private Function ConvertData(ByVal sourceTimeSpan As TimeSpan) As Double
Dim convertedValue As Double = 0
If DataConverter.CanConvert(Of Double)(sourceTimeSpan) Then
convertedValue = DataConverter.Convert(Of Double)(sourceTimeSpan)
End If
Return convertedValue
End Function
private double ConvertData(TimeSpan sourceTimeSpan)
{
double convertedValue = 0;
if (DataConverter.CanConvert<double>(sourceTimeSpan))
convertedValue = DataConverter.Convert<double>(sourceTimeSpan);
return convertedValue;
}
Private Function ConvertData(ByVal sourcePrecisionTimeSpan As PrecisionTimeSpan) As Double
Dim convertedValue As Double = 0
If DataConverter.CanConvert(Of Double)(sourcePrecisionTimeSpan) Then
convertedValue = DataConverter.Convert(Of Double)(sourcePrecisionTimeSpan)
End If
Return convertedValue
End Function
private double ConvertData(PrecisionTimeSpan sourcePrecisionTimeSpan)
{
double convertedValue = 0;
if (DataConverter.CanConvert<double>(sourcePrecisionTimeSpan))
convertedValue = DataConverter.Convert<double>(sourcePrecisionTimeSpan);
return convertedValue;
}
Private Sub DisplayWaveform(ByVal waveform As DigitalWaveform)
For Each signal As DigitalWaveformSignal In waveform.Signals
For Each state As DigitalState In signal.States
Debug.Write(String.Format("{0,-20}", state))
Next
Debug.WriteLine("")
Next
End Sub
private void DisplayWaveform(DigitalWaveform waveform)
{
foreach(DigitalWaveformSignal signal in waveform.Signals)
{
foreach(DigitalState state in signal.States)
{
Debug.Write(String.Format("{0,-20}", state));
}
Debug.WriteLine("");
}
}
Dim buffer As NationalInstruments.DataInfrastructure.Buffer(Of DigitalSample) = digitalWaveform.GetBuffer(True)
For i As Integer = 0 To (buffer.Size - 1)
'Access digital samples using an indexer property to write sample values to an output window.
Debug.WriteLine(buffer(i))
Next
NationalInstruments.DataInfrastructure.Buffer<DigitalSample> buffer = digitalWaveform.GetBuffer(true);
for (int i = 0; i < buffer.Size; i++)
{
// Access digital samples using an indexer property to write sample values to an output window.
Debug.WriteLine(buffer[i]);
}
Dim emptySample As New DigitalSample(New DigitalState(digitalWaveform.Signals.Count) {})
Dim writableBuffer As WritableBuffer(Of DigitalSample) = digitalWaveform.GetWritableBuffer()
For i As Integer = 0 To writableBuffer.Size - 1
'Reset all digital samples in the waveform.
writableBuffer(i) = emptySample
Next
DigitalSample emptySample = new DigitalSample(new DigitalState[digitalWaveform.Signals.Count]);
WritableBuffer<DigitalSample> writableBuffer = digitalWaveform.GetWritableBuffer();
for (int i = 0; i < writableBuffer.Size; i++)
{
// Reset all digital samples in the waveform.
writableBuffer[i] = emptySample;
}
Dim dateTimeBuffer As NationalInstruments.DataInfrastructure.Buffer(Of DateTime) = digitalWaveform.GetTimeStampBuffer()
For i As Integer = 0 To dateTimeBuffer.Size - 1
'Access buffer samples using an indexer property and write the timestamp to output window.
Debug.WriteLine(dateTimeBuffer(i))
Next
NationalInstruments.DataInfrastructure.Buffer<DateTime> dateTimeBuffer= digitalWaveform.GetTimeStampBuffer();
for (int i = 0; i < dateTimeBuffer.Size; i++)
{
// Access buffer samples using an indexer property and write the timestamp to output window.
Debug.WriteLine(dateTimeBuffer[i]);
}
Dim precisionDateTimeBuffer As NationalInstruments.DataInfrastructure.Buffer(Of PrecisionDateTime) = digitalWaveform.GetPrecisionTimeStampBuffer()
For i As Integer = 0 To precisionDateTimeBuffer.Size - 1
'Access buffer samples using an indexer property and write the precision time stamp to an output window.
Debug.WriteLine(precisionDateTimeBuffer(i))
Next
NationalInstruments.DataInfrastructure.Buffer<PrecisionDateTime> precisionDateTimeBuffer = digitalWaveform.GetPrecisionTimeStampBuffer();
for (int i = 0; i < precisionDateTimeBuffer.Size; i++)
{
// Access buffer samples using an indexer property and write the precision time stamp to an output window.
Debug.WriteLine(precisionDateTimeBuffer[i]);
}
String.Format(EngineeringFormatInfo.Default, "{0:ee}", 12345.67) ' Returns "12.346e+3"
String.Format(EngineeringFormatInfo.Default, "{0:ee1}", 12345.67) ' Returns "12.3e+3"
String.Format(EngineeringFormatInfo.Default, "{0:ee'Hz'}", 12345.67) ' Returns "12.346e+3Hz"
String.Format(EngineeringFormatInfo.Default, "{0:ee1'Hz'}", 12345.67) ' Returns "12.3e+3Hz"
String.Format(EngineeringFormatInfo.Default, "{0:EE}", 12345.67) ' Returns "12.346E+3"
String.Format(EngineeringFormatInfo.Default, "{0:EE1}", 12345.67) ' Returns "12.3E+3"
String.Format(EngineeringFormatInfo.Default, "{0:EE'Hz'}", 12345.67) ' Returns "12.346E+3Hz"
String.Format(EngineeringFormatInfo.Default, "{0:EE1'Hz'}", 12345.67) ' Returns "12.3E+3Hz"
String.Format(EngineeringFormatInfo.Default, "{0:eee}", 12345.67) ' Returns "12.346e+003"
String.Format(EngineeringFormatInfo.Default, "{0:eee1}", 12345.67) ' Returns "12.3e+003"
String.Format(EngineeringFormatInfo.Default, "{0:eee'Hz'}", 12345.67) ' Returns "12.346e+003Hz"
String.Format(EngineeringFormatInfo.Default, "{0:eee1'Hz'}", 12345.67) ' Returns "12.3e+003Hz"
String.Format(EngineeringFormatInfo.Default, "{0:EEE}", 12345.67) ' Returns "12.346E+003"
String.Format(EngineeringFormatInfo.Default, "{0:EEE1}", 12345.67) ' Returns "12.3E+003"
String.Format(EngineeringFormatInfo.Default, "{0:EEE'Hz'}", 12345.67) ' Returns "12.346E+003Hz"
String.Format(EngineeringFormatInfo.Default, "{0:EEE1'Hz'}", 12345.67) ' Returns "12.3E+003Hz"
String.Format(EngineeringFormatInfo.Default, "{0:ss}", 12345.67) ' Returns "12.346kilo"
String.Format(EngineeringFormatInfo.Default, "{0:ss1}", 12345.67) ' Returns "12.3kilo"
String.Format(EngineeringFormatInfo.Default, "{0:ss'Hz'}", 12345.67) ' Returns "12.346kiloHz"
String.Format(EngineeringFormatInfo.Default, "{0:ss1'Hz'}", 12345.67) ' Returns "12.3kiloHz"
String.Format(EngineeringFormatInfo.Default, "{0:s}", 12345.67) ' Returns "12.346k"
String.Format(EngineeringFormatInfo.Default, "{0:s1}", 12345.67) ' Returns "12.3k"
String.Format(EngineeringFormatInfo.Default, "{0:s'Hz'}", 12345.67) ' Returns "12.346kHz"
String.Format(EngineeringFormatInfo.Default, "{0:s1'Hz'}", 12345.67) ' Returns "12.3kHz"
String.Format(EngineeringFormatInfo.Default, "{0:SS}", 12345.67) ' Returns "12.346 kilo"
String.Format(EngineeringFormatInfo.Default, "{0:SS1}", 12345.67) ' Returns "12.3 kilo"
String.Format(EngineeringFormatInfo.Default, "{0:SS'Hz'}", 12345.67) ' Returns "12.346 kiloHz"
String.Format(EngineeringFormatInfo.Default, "{0:SS1'Hz'}", 12345.67) ' Returns "12.3 kiloHz"
String.Format(EngineeringFormatInfo.Default, "{0:S}", 12345.67) ' Returns "12.346 k"
String.Format(EngineeringFormatInfo.Default, "{0:S1}", 12345.67) ' Returns "12.3 k"
String.Format(EngineeringFormatInfo.Default, "{0:S'Hz'}", 12345.67) ' Returns "12.346 kHz"
String.Format(EngineeringFormatInfo.Default, "{0:S1'Hz'}", 12345.67) ' Returns "12.3 kHz"
String.Format(EngineeringFormatInfo.Default, "{0:ee}", 12345.67); // Returns "12.346e+3"
String.Format(EngineeringFormatInfo.Default, "{0:ee1}", 12345.67); // Returns "12.3e+3"
String.Format(EngineeringFormatInfo.Default, "{0:ee'Hz'}", 12345.67); // Returns "12.346e+3Hz"
String.Format(EngineeringFormatInfo.Default, "{0:ee1'Hz'}", 12345.67); // Returns "12.3e+3Hz"
String.Format(EngineeringFormatInfo.Default, "{0:EE}", 12345.67); // Returns "12.346E+3"
String.Format(EngineeringFormatInfo.Default, "{0:EE1}", 12345.67); // Returns "12.3E+3"
String.Format(EngineeringFormatInfo.Default, "{0:EE'Hz'}", 12345.67); // Returns "12.346E+3Hz"
String.Format(EngineeringFormatInfo.Default, "{0:EE1'Hz'}", 12345.67); // Returns "12.3E+3Hz"
String.Format(EngineeringFormatInfo.Default, "{0:eee}", 12345.67); // Returns "12.346e+003"
String.Format(EngineeringFormatInfo.Default, "{0:eee1}", 12345.67); // Returns "12.3e+003"
String.Format(EngineeringFormatInfo.Default, "{0:eee'Hz'}", 12345.67); // Returns "12.346e+003Hz"
String.Format(EngineeringFormatInfo.Default, "{0:eee1'Hz'}", 12345.67); // Returns "12.3e+003Hz"
String.Format(EngineeringFormatInfo.Default, "{0:EEE}", 12345.67); // Returns "12.346E+003"
String.Format(EngineeringFormatInfo.Default, "{0:EEE1}", 12345.67); // Returns "12.3E+003"
String.Format(EngineeringFormatInfo.Default, "{0:EEE'Hz'}", 12345.67); // Returns "12.346E+003Hz"
String.Format(EngineeringFormatInfo.Default, "{0:EEE1'Hz'}", 12345.67); // Returns "12.3E+003Hz"
String.Format(EngineeringFormatInfo.Default, "{0:ss}", 12345.67); // Returns "12.346kilo"
String.Format(EngineeringFormatInfo.Default, "{0:ss1}", 12345.67); // Returns "12.3kilo"
String.Format(EngineeringFormatInfo.Default, "{0:ss'Hz'}", 12345.67); // Returns "12.346kiloHz"
String.Format(EngineeringFormatInfo.Default, "{0:ss1'Hz'}", 12345.67); // Returns "12.3kiloHz"
String.Format(EngineeringFormatInfo.Default, "{0:s}", 12345.67); // Returns "12.346k"
String.Format(EngineeringFormatInfo.Default, "{0:s1}", 12345.67); // Returns "12.3k"
String.Format(EngineeringFormatInfo.Default, "{0:s'Hz'}", 12345.67); // Returns "12.346kHz"
String.Format(EngineeringFormatInfo.Default, "{0:s1'Hz'}", 12345.67); // Returns "12.3kHz"
String.Format(EngineeringFormatInfo.Default, "{0:SS}", 12345.67); // Returns "12.346 kilo"
String.Format(EngineeringFormatInfo.Default, "{0:SS1}", 12345.67); // Returns "12.3 kilo"
String.Format(EngineeringFormatInfo.Default, "{0:SS'Hz'}", 12345.67); // Returns "12.346 kiloHz"
String.Format(EngineeringFormatInfo.Default, "{0:SS1'Hz'}", 12345.67); // Returns "12.3 kiloHz"
String.Format(EngineeringFormatInfo.Default, "{0:S}", 12345.67); // Returns "12.346 k"
String.Format(EngineeringFormatInfo.Default, "{0:S1}", 12345.67); // Returns "12.3 k"
String.Format(EngineeringFormatInfo.Default, "{0:S'Hz'}", 12345.67); // Returns "12.346 kHz"
String.Format(EngineeringFormatInfo.Default, "{0:S1'Hz'}", 12345.67); // Returns "12.3 kHz"
Dim s As String = "9.50"
Dim x As Double
Dim info As EngineeringFormatInfo = New EngineeringFormatInfo()
Dim success As Boolean = info.TryParse("S", s, CultureInfo.CurrentCulture, x)
string s = "9.50";
double x;
EngineeringFormatInfo info = new EngineeringFormatInfo();
bool success = info.TryParse("S", s, CultureInfo.CurrentCulture, out x);
Dim s As String = "9.50"
Dim info As EngineeringFormatInfo = New EngineeringFormatInfo()
Dim x As Double = info.Parse("S", s)
string s = "9.50";
EngineeringFormatInfo info = new EngineeringFormatInfo();
double x = info.Parse("S", s);
Dim s As String = "9.50"
Dim info As EngineeringFormatInfo = New EngineeringFormatInfo()
Dim x As Double = info.Parse("S", s, CultureInfo.CurrentCulture)
string s = "9.50";
EngineeringFormatInfo info = new EngineeringFormatInfo();
double x = info.Parse("S", s, CultureInfo.CurrentCulture);
' The styles variable is a ComboBox control. FillStyle is a type that
' derives from EnumObject.
For Each style As FillStyle In EnumObject.GetValues(GetType(FillStyle))
styles.Items.Add(style)
Next
// The styles variable is a ComboBox control. FillStyle is a type that
// derives from EnumObject.
foreach (FillStyle style in EnumObject.GetValues(typeof(FillStyle)))
styles.Items.Add(style);
' Example of the PrecisionTimeSpan properties.
Imports NationalInstruments
Module PrecisionTimeSpanDemo
Const headerFormat As String = vbCrLf & "{0,-45}"
Const dataFormat As String = "{0,-12}{1,8} {2,-18}{3,21}"
' Display the properties of the PrecisionTimeSpan parameter.
Sub ShowPrecisionTimeSpanProperties(ByVal interval As PrecisionTimeSpan)
Console.WriteLine("{0,21}", interval)
Console.WriteLine(dataFormat, _
"Days", interval.Days, "TotalDays", interval.TotalDays)
Console.WriteLine(dataFormat, "Hours", interval.Hours, _
"TotalHours", interval.TotalHours)
Console.WriteLine(dataFormat, "Minutes", interval.Minutes, _
"TotalMinutes", interval.TotalMinutes)
Console.WriteLine(dataFormat, "Seconds", interval.Seconds, _
"TotalSeconds", interval.TotalSeconds)
Console.WriteLine(dataFormat, _
"Milliseconds", interval.Milliseconds, _
"TotalMilliseconds", interval.TotalMilliseconds)
Console.WriteLine(dataFormat, _
Nothing, Nothing, "FractionalSecondTicks", interval.FractionalSecondTicks)
Console.WriteLine(dataFormat, _
Nothing, Nothing, "FractionalSeconds", interval.FractionalSeconds)
End Sub
Sub Main()
Console.WriteLine( _
"This example of the PrecisionTimeSpan class generates " & vbCrLf & _
"the following output. It creates several PrecisionTimeSpan " & vbCrLf & _
"objects and displays the values of the properties for each")
' Create and display a PrecisionTimeSpan value of 1 fractional second tick.
Console.Write(headerFormat, "PrecisionTimeSpan( 0, 1 )")
ShowPrecisionTimeSpanProperties(New PrecisionTimeSpan(0, 1))
' Create a PrecisionTimeSpan value with both whole seconds and fractional second ticks.
Console.Write(headerFormat, "PrecisionTimeSpan( 123456, 111222333444555 )")
ShowPrecisionTimeSpanProperties(New PrecisionTimeSpan(123456, 111222333444555))
' Create a PrecisionTimeSpan value from 1.5 seconds.
Console.Write(headerFormat, "PrecisionTimeSpan( 1.5 )")
ShowPrecisionTimeSpanProperties(New PrecisionTimeSpan(1.5))
' This TimeSpan is based on a number of days.
Console.Write(headerFormat, "FromDays( 20.84745602 )")
ShowPrecisionTimeSpanProperties(PrecisionTimeSpan.FromDays(20.84745602))
' Create a PrecisionTimeSpan value from a TimeSpan object.
Console.Write(headerFormat, "FromTimeSpan(new TimeSpan( 10, 20, 30, 40, 50 ))")
ShowPrecisionTimeSpanProperties(PrecisionTimeSpan.FromTimeSpan(New TimeSpan(10, 20, 30, 40, 50)))
End Sub
End Module
' This example of the PrecisionTimeSpan class generates
' the following output. It creates several PrecisionTimeSpan
' objects and displays the values of the properties for each
'
' PrecisionTimeSpan( 0, 1 ) 00:00:00
' Days 0 TotalDays 6.27431812780963E-25
' Hours 0 TotalHours 1.50583635067431E-23
' Minutes 0 TotalMinutes 9.03501810404587E-22
' Seconds 0 TotalSeconds 5.42101086242752E-20
' Milliseconds 0 TotalMilliseconds 5.42101086242752E-17
' FractionalSecondTicks 1
' FractionalSeconds 5.42101086242752E-20
'
' PrecisionTimeSpan( 123456, 111222333444555 ) 1.10:17:36.0000060
' Days 1 TotalDays 1.42888888895867
' Hours 10 TotalHours 34.2933333350082
' Minutes 17 TotalMinutes 2057.60000010049
' Seconds 36 TotalSeconds 123456.000006029
' Milliseconds 0 TotalMilliseconds 123456000.006029
' FractionalSecondTicks 111222333444555
' FractionalSeconds 6.02937477747469E-06
'
' PrecisionTimeSpan( 1.5 ) 00:00:01.5000000
' Days 0 TotalDays 1.73611111111111E-05
' Hours 0 TotalHours 0.000416666666666667
' Minutes 0 TotalMinutes 0.025
' Seconds 1 TotalSeconds 1.5
' Milliseconds 500 TotalMilliseconds 1500
' FractionalSecondTicks 9223372036854775808
' FractionalSeconds 0.5
'
' FromDays( 20.84745602 ) 20.20:20:20.2001280
' Days 20 TotalDays 20.84745602
' Hours 20 TotalHours 500.33894448
' Minutes 20 TotalMinutes 30020.3366688
' Seconds 20 TotalSeconds 1801220.200128
' Milliseconds 200 TotalMilliseconds 1801220200.128
' FractionalSecondTicks 3691709997923696640
' FractionalSeconds 0.200127999996766
'
' FromTimeSpan(new TimeSpan( 10, 20, 30, 40, 50 )) 10.20:30:40.0500000
' Days 10 TotalDays 10.8546302083333
' Hours 20 TotalHours 260.511125
' Minutes 30 TotalMinutes 15630.6675
' Seconds 40 TotalSeconds 937840.05
' Milliseconds 49 TotalMilliseconds 937840050
' FractionalSecondTicks 922337203685477580
' FractionalSeconds 0.05
// Example of the PrecisionTimeSpan properties.
using System;
using NationalInstruments;
public class PrecisionTimeSpanDemo
{
const string headerFormat = "\n{0,-48}";
const string dataFormat = "{0,-12}{1,8} {2,-21}{3,21}";
// Display the properties of the TimeSpan parameter.
static void ShowPrecisionTimeSpanProperties(PrecisionTimeSpan interval)
{
Console.WriteLine("{0,21}", interval);
Console.WriteLine(dataFormat, "Days", interval.Days,
"TotalDays", interval.TotalDays);
Console.WriteLine(dataFormat, "Hours", interval.Hours,
"TotalHours", interval.TotalHours);
Console.WriteLine(dataFormat, "Minutes", interval.Minutes,
"TotalMinutes", interval.TotalMinutes);
Console.WriteLine(dataFormat, "Seconds", interval.Seconds,
"TotalSeconds", interval.TotalSeconds);
Console.WriteLine(dataFormat, "Milliseconds",
interval.Milliseconds, "TotalMilliseconds",
interval.TotalMilliseconds);
Console.WriteLine(dataFormat, null, null,
"FractionalSecondTicks", interval.FractionalSecondTicks);
Console.WriteLine(dataFormat, null, null,
"FractionalSeconds", interval.FractionalSeconds);
}
static void Main()
{
Console.WriteLine(
"This example of the PrecisionTimeSpan class generates\n" +
"the following output. It creates several PrecisionTimeSpan\n" +
"objects and displays the values of the properties for each.");
// Create and display a PrecisionTimeSpan value of 1 fractional second tick.
Console.Write(headerFormat, "PrecisionTimeSpan( 0, 1 )");
ShowPrecisionTimeSpanProperties(new PrecisionTimeSpan(0, 1));
// Create a PrecisionTimeSpan value with both whole seconds and fractional second ticks.
Console.Write(headerFormat, "PrecisionTimeSpan( 123456, 111222333444555 )");
ShowPrecisionTimeSpanProperties(new PrecisionTimeSpan(123456, 111222333444555));
// Create a PrecisionTimeSpan value from 1.5 seconds.
Console.Write(headerFormat, "PrecisionTimeSpan( 1.5 )");
ShowPrecisionTimeSpanProperties(new PrecisionTimeSpan(1.5));
// This PrecisionTimeSpan is based on a number of days.
Console.Write(headerFormat, "FromDays( 20.84745602 )");
ShowPrecisionTimeSpanProperties(PrecisionTimeSpan.FromDays(20.84745602));
// Create a PrecisionTimeSpan value from a TimeSpan object.
Console.Write(headerFormat, "FromTimeSpan(new TimeSpan(10, 20, 30, 40, 50))");
ShowPrecisionTimeSpanProperties(PrecisionTimeSpan.FromTimeSpan(new TimeSpan(10, 20, 30, 40, 50)));
}
}
/*
This example of the PrecisionTimeSpan class generates
the following output. It creates several PrecisionTimeSpan
objects and displays the values of the properties for each.
PrecisionTimeSpan( 0, 1 ) 00:00:00
Days 0 TotalDays 6.27431812780963E-25
Hours 0 TotalHours 1.50583635067431E-23
Minutes 0 TotalMinutes 9.03501810404587E-22
Seconds 0 TotalSeconds 5.42101086242752E-20
Milliseconds 0 TotalMilliseconds 5.42101086242752E-17
FractionalSecondTicks 1
FractionalSeconds 5.42101086242752E-20
PrecisionTimeSpan( 123456, 111222333444555 ) 1.10:17:36.0000060
Days 1 TotalDays 1.42888888895867
Hours 10 TotalHours 34.2933333350082
Minutes 17 TotalMinutes 2057.60000010049
Seconds 36 TotalSeconds 123456.000006029
Milliseconds 0 TotalMilliseconds 123456000.006029
FractionalSecondTicks 111222333444555
FractionalSeconds 6.02937477747469E-06
PrecisionTimeSpan( 1.5 ) 00:00:01.5000000
Days 0 TotalDays 1.73611111111111E-05
Hours 0 TotalHours 0.000416666666666667
Minutes 0 TotalMinutes 0.025
Seconds 1 TotalSeconds 1.5
Milliseconds 500 TotalMilliseconds 1500
FractionalSecondTicks 9223372036854775808
FractionalSeconds 0.5
FromDays( 20.84745602 ) 20.20:20:20.2001280
Days 20 TotalDays 20.84745602
Hours 20 TotalHours 500.33894448
Minutes 20 TotalMinutes 30020.3366688
Seconds 20 TotalSeconds 1801220.200128
Milliseconds 200 TotalMilliseconds 1801220200.128
FractionalSecondTicks 3691709997923696640
FractionalSeconds 0.200127999996766
FromTimeSpan(new TimeSpan(10, 20, 30, 40, 50)) 10.20:30:40.0500000
Days 10 TotalDays 10.8546302083333
Hours 20 TotalHours 260.511125
Minutes 30 TotalMinutes 15630.6675
Seconds 40 TotalSeconds 937840.05
Milliseconds 49 TotalMilliseconds 937840050
FractionalSecondTicks 922337203685477580
FractionalSeconds 0.05
*/
Private Sub DisplaySpectrum(Of TData)(ByVal spectrum As Spectrum(Of TData))
For Each sample As SpectrumSample(Of TData) In spectrum.Samples
Debug.WriteLine(String.Format("{0}", sample.Value))
Next
End Sub
private void DisplaySpectrum<TData>(Spectrum<TData> spectrum)
{
foreach (SpectrumSample<TData> sample in spectrum.Samples)
{
Debug.WriteLine(String.Format("{0}", sample.Value));
}
}
Dim buffer As NationalInstruments.DataInfrastructure.Buffer(Of Double) = spectrum.GetBuffer(True)
For i As Integer = 0 To (buffer.Size - 1)
'Access data samples using an indexer property to write sample values to an output window.
Debug.WriteLine(buffer(i))
Next
NationalInstruments.DataInfrastructure.Buffer<double> buffer = spectrum.GetBuffer(true);
for (int i = 0; i < buffer.Size; i++)
{
// Access data samples using an indexer property to write sample values to an output window.
Debug.WriteLine(buffer[i]);
}
Dim r As New Random()
Dim writableBuffer As NationalInstruments.DataInfrastructure.WritableBuffer(Of Double) = spectrum.GetWritableBuffer()
For i As Integer = 0 To writableBuffer.Size - 1
'Add a random value.
writableBuffer(i) += r.NextDouble()
Next
Random r = new Random();
NationalInstruments.DataInfrastructure.WritableBuffer<double> writableBuffer = spectrum.GetWritableBuffer();
for (int i = 0; i < writableBuffer.Size; i++)
{
// Add a random value.
writableBuffer[i] += r.NextDouble();
}