RandomExtensionsNextDateTime Method

Returns a random DateTime that is between the specified range.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 7.2.0
C#
public static DateTime NextDateTime(
	this Random random,
	DateTime? minValue = null,
	DateTime? maxValue = null
)

Parameters

random  Random
The Random instance to use.
minValue  NullableDateTime  (Optional)
The inclusive lower bound of the random DateTime returned or to use DateTime.MinValue. This parameter is optional.
Default value: .
maxValue  NullableDateTime  (Optional)
The inclusive upper bound of the random DateTime returned or to use DateTime.MaxValue. This parameter is optional.
Default value: .

Return Value

DateTime
A DateTime value that is in the specified range.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Random. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

The Kind property of minValue and maxValue is ignored.

The Kind property of the generated DateTime instances is always Unspecified.

Exceptions

ArgumentNullExceptionrandom is .
ArgumentOutOfRangeExceptionmaxValue is less than minValue.

See Also