简体   繁体   中英

MemoryStream to sbyte[]

I'm still trying to add a jpeg image to a person in Open LDAP, using Novell's c# libraries:

Openldap: Add jpegPhoto to inetOrgPerson

There is a constructor for Novell.Directory.Ldap.LdapAttribute the with the following signature:

public LdapAttribute(string attrName, sbyte[] attrBytes)

So, I plan to use this one. But, how to convert a jpeg image from a MemoreyStream to sbyte[]?

MemoryStream.ToArray() 

method returns byte[] and I don't know how to do it.

您可以像这样转换数组:

Array.ConvertAll(bytes, b => (sbyte)b)

On the CLR you can constant-time convert a byte[] to an sbyte[] . See my previous answer on this little-known trick.

(sbyte[])(object)MemoryStream.ToArray(); //compiles and runs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM