小编Ale*_*ria的帖子

带接口的C#泛型

我正在尝试学习如何使用c#创建泛型类.有人可以解释为什么我运行这个程序时出现编译错误.

我创建了IZooAnimal接口.所有动物园动物都将实现此界面.

public interface IZooAnimal
{
    string Id { get; set; }
}

public class Lion : IZooAnimal
{
    string Id { get; set; }
}

public class Zebra : IZooAnimal
{
    public string Id { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

ZooCage将容纳相同类型的动物

public class ZooCage<T> where T : IZooAnimal
{
    public IList<T> Animals { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

动物园类有笼子

public class Zoo
{
    public IList<ZooCage<IZooAnimal>> ZooCages { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

使用类的程序

class Program
{
    static void Main(string[] args)
    {
        var …
Run Code Online (Sandbox Code Playgroud)

c# generics

5
推荐指数
1
解决办法
470
查看次数

File.ReadAllBytes 抛出 IOException 表示该进程无法访问该文件,因为它正被另一个进程使用

File.ReadAllBytes 在两次调用之间没有足够的调用间隔时会导致 IOException 吗?

当我设置网格的 Row 和 Col 时,它会触发 RowColChange 事件。RowColChange 有一些代码可以使用 File.ReadAllBytes 打开同一个文件。我知道 ReadAllBytes 内部在 FileStream 上使用 using 因此文件流在使用后关闭。但是在告诉操作系统文件被释放时是否可能有一些延迟,因此 File.ReadAllBytes 的后续使用可能会失败并引发异常。有什么想法吗?谢谢!

grid.Row = 0
grid.Row = 1
grid.Col = 3


Private Sub grid_RowColChange(ByVal sender As Object, ByVal e As System.EventArgs) Handles grid.RowColChange
    'Is it possible to get IOException saying the process can't access the file because it is being used by another process.
     Display(File.ReadAllBytes(filePath))
End Sub
Run Code Online (Sandbox Code Playgroud)

.net vb.net system.io.file

5
推荐指数
2
解决办法
5899
查看次数

标签 统计

.net ×1

c# ×1

generics ×1

system.io.file ×1

vb.net ×1