c# - 如何像 C++ 一样在 C# 中初始化
问题描述
如何在 C# 中初始化多个变量?
class file_list_output
{
public file_list_output(ListView v, const int max) => veiw = v => max_ext_allowed = max;
}
想不通
解决方案
你需要这样做:
所以你的类有两个属性:
public int Max_ext_allowed {get; private set;}
public ListView View {get; private set;}
//To do an expression bodied constructor
//The fat arrow => is replacing the typical { }
//And the next portion (View, Max_ext_allowed) is saying these are the properties being initialized
//Finally the last portion (v, max) is the set of values to set the properties to
public file_list_input(ListView v, int max) => (View, Max_ext_allowed) = (v, max);
推荐阅读
- nginx - 在 openresty 中获取输入标头
- vb.net - 在我什至调用表单之前,vb.net 正在调用表单“新”例程
- visual-studio - 包“Microsoft.VisualStudio.MinShell.Msi,version=16.9.31025.104”的解决方法无法下载
- python - 如何过滤具有动态列数的数据框?
- javascript - 带有反向代理的 url 只查询第一个 url 参数
- java - 代号一 Android 构建错误 - android.licenseKey
- r - 在 geom_line() 图上创建和标记点
- java - 在 Apache Camel 中实现变更数据捕获
- amazon-web-services - 在 AWS SES 中为转发的电子邮件发送退回电子邮件时出现收件人错误
- php - 为什么我得到 spatie/laravel-cors[1.2.0, ..., 1.2.2] 需要照明/支持 5.5.*|5.6.* 当我运行 composer require spatie/laravel-cors