【问题标题】:How can you tell the source of the data when using the Stream.BeginRead Method?使用 Stream.BeginRead 方法时如何判断数据的来源?
【发布时间】:2010-06-10 00:31:47
【问题描述】:

当使用 Stream.BeginRead 方法时,您正在从流中读取数据到内存中,如何确定您从哪里读取数据?

见: http://msdn.microsoft.com/en-us/library/system.io.stream.beginread.aspx

在参数列表中,我没有看到说明从何处读取数据的参数:

参数

  • buffer 类型:System.Byte[] 将数据读入的缓冲区。
  • offset 类型:System.Int32 缓冲区中开始写入从流中读取的数据的字节偏移量
  • count 类型:System.Int32 要读取的最大字节数。
  • callback 类型:System.AsyncCallback 可选的异步回调,在读取完成时调用。
  • state 类型:System.Object 用户提供的对象,用于将此特定异步读取请求与其他读取请求区分开来 请求。

【问题讨论】:

    标签: c# stream beginread


    【解决方案1】:

    根据Position property 确定,它会从流到达的任何位置读取数据。

    请注意,并非所有流都支持搜索,因此您不一定要设置Position

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-06
      • 2011-12-22
      • 1970-01-01
      • 2012-04-14
      • 2021-08-15
      相关资源
      最近更新 更多