C# FileStream.Read Method

简介: Reads a block of bytes from the stream and writes the data in a given buffer. public override int Read( byte[] array, int offset, int count) Parameters arrayType: System.Byte[] W

Reads a block of bytes from the stream and writes the data in a given buffer.

public override int Read(
	byte[] array,
	int offset,
	int count
)

Parameters

array
Type:  System.Byte []

When this method returns, contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.

offset
Type:  System.Int32

The byte offset in array at which the read bytes will be placed.

count
Type:  System.Int32

The maximum number of bytes to read.

Return Value

Type:  System.Int32
The total number of bytes read into the buffer. This might be less than the number of bytes requested if that number of bytes are not currently available, or zero if the end of the stream is reached.
Exception Condition
ArgumentNullException

array is null.

ArgumentOutOfRangeException

offset or count is negative.

NotSupportedException

The stream does not support reading.

IOException

An I/O error occurred.

ArgumentException

offset and count describe an invalid range in array.

ObjectDisposedException

Methods were called after the stream was closed.


相关文章
|
C# 设计模式 .NET
使用C# (.NET Core) 实现简单工厂(Simple Factory) 和工厂方法设计模式 (Factory Method Pattern)
本文源自深入浅出设计模式. 只不过我是使用C#/.NET Core实现的例子.   前言 当你看见new这个关键字的时候, 就应该想到它是具体的实现. 这就是一个具体的类, 为了更灵活, 我们应该使用的是接口(interface).
1749 0
|
算法 C# Java
使用C# (.NET Core) 实现模板方法模式 (Template Method Pattern)
本文的概念内容来自深入浅出设计模式一书. 项目需求 有一家咖啡店, 供应咖啡和茶, 它们的工序如下: 咖啡: 茶: 可以看到咖啡和茶的制作工序是差不多的, 都是有4步, 其中有两步它们两个是一样的, 另外两步虽然具体内容不一样, 但是都做做的同一类工作.
1658 0
|
关系型数据库 Go C#
C#设计模式之二工厂方法模式(Factory Method Pattern)【创建型】
原文:C#设计模式之二工厂方法模式(Factory Method Pattern)【创建型】 一、引言       在上一篇文章中我们讲解了过渡的一种模式叫做【简单工厂】,也有叫【静态工厂】的,通过对简单工厂模式得了解,我们也发现了它的缺点,就是随着需求的变化我们要不停地修改工厂里面的方法的代码,需求变化越多,里面的If--Else--也越多,这样就会造成简单工厂的实现逻辑过于复杂。
1804 0
|
C#
艾伟:C# Design Patterns (1) - Factory Method
Simple Factory Pattern (简单工厂模式) 特性: 把类的实例化工作,集中到一个「工厂类」去处理,亦即将 new instance 的工作,都交给一个「工厂」去处理,而不要分散写在各个类中。
1060 0
|
C#
艾伟_转载:C# Design Patterns (1) - Factory Method
Simple Factory Pattern (简单工厂模式) 特性: 把类的实例化工作,集中到一个「工厂类」去处理,亦即将 new instance 的工作,都交给一个「工厂」去处理,而不要分散写在各个类中。
1117 0
C# [method Modifiers] abstract virtual override new
abstract :表示方法是抽象方法,在子类中必须重写。抽象方法所在的类必须是抽象类,即用abstract modifiers;virtual:表示此方法是virtual方法,除了在子类中可以重写外(在子类中也可直接使用),和普通方法完全一样;override:表示重写父类的virtual方法;new: 显式隐藏从基类继承的成员; 区别: virtual:标记方法为虚方法1.
921 0