Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save byte[] in c# application settings

Tags:

I am trying to save a byte array (byte[]) in c# application settings that is returned by Object List View.

Can anyone give me a solution on how to save byte array in c# application settings? or some trick on how to convert byte[] to something like a string then store, then retrieve and again convert it to byte array and give it back to object list view.

like image 348
Imran Shafqat Avatar asked Sep 08 '12 11:09

Imran Shafqat


People also ask

How do I save a byte file?

Java – How to save byte[] to a filewrite is the simplest solution to save byte[] to a file. // bytes = byte[] Path path = Paths. get("/path/file"); Files. write(path, bytes);

What is a byte [] in C#?

In C#, byte is the data type for 8-bit unsigned integers, so a byte[] should be an array of integers who are between 0 and 255, just like an char[] is an array of characters.

What does [] mean in array?

*array[] means array of pointers, in your example: char *somarray[] = {"Hello"};

What is byte type array?

A byte array is simply a collection of bytes. The bytearray() method returns a bytearray object, which is an array of the specified bytes. The bytearray class is a mutable array of numbers ranging from 0 to 256.


1 Answers

One of the most common ways to make a string from an array of bytes is encoding them in Base-64:

string encoded = System.Convert.ToBase64String(toEncodeAsBytes); 

Use

byte[] bytes = System.Convert.FromBase64String(encoded); 

to get your bytes back.

like image 99
Sergey Kalinichenko Avatar answered Sep 20 '22 16:09

Sergey Kalinichenko