210514随笔记

c#中如何将一个数组拆分多个小数组

在这里插入图片描述

 int[] data = {1,2,3,4,5,6,7,8,9};
int[][] result = Enumerable.Range(0, data.Count() / 3).Select(x => data.Skip(x*3).Take(3).ToArray()).ToArray();

sql中添加语句自增

create table test(name varchar(20),password int)
//添加自增
alter table test add id int identity(1,1)//前一个1是自增开始的数字,后一个1是自增的间隔
alter table test drop column id


select * from test

insert into test values('we',23)
insert into test values('www',233)

truncate table test
delete from test where name='we'
drop table test

通过sql给表添加字段

alter table 表名 add 字段 数据类型(长度);
亲测有效!
补充:当数据类型为date时,不用加上长度
即sql为:alter table 表名 add 字段 date

stream 与byte[] 转换

//stream 转为byte[] 
public byte[] stream2byte(Stream stream)
{
    byte[]  buffer= new byte[stream.length];
    stream.Read(buffer,0,buffer.length);
    return buffer;
}
//byte[] 转stream
public stream byte2stream(byte[] buffer)
{
    stream stream= new MemoryStream(buffer);
    stream.Seek(0,SeekOrigin.Begin);
    //设置stream的position为流的开始
    return stream;
}

//stream写到文件
public void stream2File(Stream stream)
{
    byte[] buffer= new buffer[stream.length];
    stream.Read(buffer,0,buffer.length);
    FileStream fs= new FileStream(filename,FileMode.Create);
    BinaryWriter writer= new BinaryWriter(fs);
    writer.Writer(buffer);
    writer.Close();
    fs.Close();
}
//读取文件到stream
public Stream file2Stream(string path)
{
    FileStream fs = new FileStream(path,fileMode.Open,FileAccess.Read);
    byte[] buffer= new byte[fs.length];
fs.Read(buffer,0,buffer.length);
Stream  stream=MemoryStream(buffer);
 stream.Seek(0,seekOrigin.Begin);
return stream;  
}

https://ask.csdn.net/questions/665249
https://blog.csdn.net/Eason_927/article/details/83415720
https://blog.csdn.net/sophiemantela/article/details/78915237

posted @ 2021-05-14 20:06  今晚打老虎!  阅读(51)  评论(0编辑  收藏  举报