.NET Framework Class Library
Binary Class

Represents an immutable block of binary data.

Namespace:  System.Data.Linq
Assembly:  System.Data.Linq (in System.Data.Linq.dll)
Syntax

Visual Basic (Declaration)
<SerializableAttribute> _
<DataContractAttribute> _
Public NotInheritable Class Binary _
    Implements IEquatable(Of Binary)
Visual Basic (Usage)
Dim instance As Binary
C#
[SerializableAttribute]
[DataContractAttribute]
public sealed class Binary : IEquatable<Binary>
Visual C++
[SerializableAttribute]
[DataContractAttribute]
public ref class Binary sealed : IEquatable<Binary^>
JScript
public final class Binary implements IEquatable<Binary>
Inheritance Hierarchy

System..::.Object
  System.Data.Linq..::.Binary
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5
See Also

Reference

Tags :


Community Content

John Paliwoda
Convert to String

If you are using ASP.Net and use the SQL Server "timestamp" datatype for concurrency, you may want to convert the "timestamp" value into a string so you can store it (e.g., on a web page). When LINQ to SQL retrieves a "timestamp" from SQL Server, it stores it in a Binary class instance. So you essentially need to convert the Binary instance to a string and then be able to convert the string to an equivalent Binary instance.

The code below provides two extension methods to do this. You can remove the "this" before the first parameter if you prefer them to be ordinary static methods. The conversion to base 64 is a precaution to ensure that the resultant string contains only displayable characters and no escape characters.

  

public static string ConvertRowVersionToString(this Binary rowVersion) {
return Convert.ToBase64String(rowVersion.ToArray());
}
public static Binary ConvertStringToRowVersion(this string rowVersion) {
return new Binary(Convert.FromBase64String(rowVersion));
}
Tags :

Rick Strahl
This type does not XmlSerialize
This type doesn't serialize so if you are planning to manually serialize an entity with say a timestamp you'll get an error during serialization initialization.

Page view tracker