How does the “Using” statement translate from C# to VB?

前端 未结 5 956
星月不相逢
星月不相逢 2020-12-03 09:20

For example:

BitmapImage bitmap = new BitmapImage();

byte[] buffer = GetHugeByteArray(); // from some external source
using (MemoryStream stream = new Memor         


        
5条回答
  •  星月不相逢
    2020-12-03 10:04

    That would be something like this:

    Dim bitmap As New BitmapImage()
    Dim buffer As Byte() = GetHugeByteArray()
    Using stream As New MemoryStream(buffer, False)
        bitmap.BeginInit()
        bitmap.CacheOption = BitmapCacheOption.OnLoad
        bitmap.StreamSource = stream
        bitmap.EndInit()
        bitmap.Freeze()
    End Using
    

提交回复
热议问题