gpt4 book ai didi

c# - 我可以在 C# *using* block 中使用不同类型的对象吗?

转载 作者:太空狗 更新时间:2023-10-29 22:02:23 25 4
gpt4 key购买 nike

using (Font font3 = new Font("Arial", 10.0f), 
font4 = new Font("Arial", 10.0f))
{
// Use font3 and font4.
}

我知道可以在 using 子句中使用多个相同类型的对象。

我不能在 using 子句中使用不同类型的对象吗?

好吧,我试过了,但尽管它们是不同的名称和不同的对象,但它们的行为相同 = 具有相同的方法集

有没有其他方法可以使用不同类型的 using 类?

如果不是,最合适的使用方式是什么?

最佳答案

using(Font f1 = new Font("Arial",10.0f))
using (Font f2 = new Font("Arial", 10.0f))
using (Stream s = new MemoryStream())
{

}

像这样吗?

关于c# - 我可以在 C# *using* block 中使用不同类型的对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3092167/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com