Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Binary Class

  Switch on low bandwidth view
.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)
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>
System..::.Object
  System.Data.Linq..::.Binary
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

.NET Framework

Supported in: 3.5
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Convert to String      John Paliwoda   |   Edit   |   Show History

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 What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker