什么是写一个简短的[]数组在C#中的文件的最佳方法是什么? [英] What's the best way to write a short[] array to a file in C#?

查看:129
本文介绍了什么是写一个简短的[]数组在C#中的文件的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有短裤的数组(简称[]),我需要写一个文件。什么是做到这一点的最快方法是什么?

I have an array of shorts (short[]) that I need to write out to a file. What's the quickest way to do this?

推荐答案

使用的BinaryWriter

Use the BinaryWriter

    static void WriteShorts(short[] values, string path)
    {
        using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
        {
            using (BinaryWriter bw = new BinaryWriter(fs))
            {
                foreach (short value in values)
                {
                    bw.Write(value);
                }
            }
        }
    }

这篇关于什么是写一个简短的[]数组在C#中的文件的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆