準備
(なし)
デザイン
- フォーム (Form1) にボタン (button1) を配置します。
- フォーム (Form1) にリストボックス (listBox1) を配置します。
サンプルコード (C#)
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
byte[] Alphabet1 = { 0x41, 0x42, 0x43 };
using (var ms = new MemoryStream())
{
ms.Write(Alphabet1, 0, Alphabet1.Length);
byte[] Alphabet2 = ms.ToArray();
foreach (byte item in Alphabet2)
{
listBox1.Items.Add((char)item);
}
}
}
}
}
解説
Byte 配列をメモリーストリームに格納したのち、メモリーストリームの内容を別の Byte 配列に格納しています。
結果
動作確認環境
Visual Studio 2022 Professional (.NET 7 C#11)
ログ
初版:2016.06.07 Visual Studio 2015 Professional (C# 6.0)
