c# - 数组中的元素可以引用数组吗?
问题描述
如果我有一个名为的数组standard
并且我想要那个数组的计数我会做standard.Count
但
如果我要string
调用一个数组doorType
并将其添加string
standard
到该数组的第一个位置,但我想参考standard.Count
有没有一种方法可以操作doorType[0].Count
,以便它获取standard
数组中的元素数?
public static List<string> doorType = new List<string>
{
nameof(standard),
nameof(original)
};
public static List<string> standard= new List<string>
{
"1",
"4",
"6"
};
我怎样才能使第二行相等?
string xform = doorType[0] + standard.Count;
string xform = doorType[0] + doorType[0].Count;
一些额外有用的代码
public static void AddDropDown(string cellInsert, string formula)
{
var cell = x.Range[cellInsert];
cell.Validation.Delete();
cell.Validation.Add(
Excel.XlDVType.xlValidateList,
Excel.XlDVAlertStyle.xlValidAlertInformation,
Excel.XlFormatConditionOperator.xlBetween,
formula,
Type.Missing);
cell.Validation.IgnoreBlank = true;
cell.Validation.InCellDropdown = true;
cell.Value = "Please Select";
}//end AddDropDown
string xform =
"=IF(B2=" + DO.quote + doorType[0] + DO.quote + "," + "E1:E" + standard.Count +
",IF(B2=" + DO.quote + doorType[1] + DO.quote + "," + "F1: F" + original.Count +
"," + "I1: I3" + "))))";
AddDropDown("B4", xform);
为了更清楚地解释,我想xform
使用以前制作的数组通过 for 循环将字符串附加到。
这都是为了将 C# 链接到 excel
解决方案
与 Sweeper 的评论相同,或者您可以创建一个类 DoorType?
public class DoorType
{
public List<string> DoorTypes { get; set; }
}
然后在您的标准列表中:
List<DoorType> standardList = new List<DoorType>();
然后您可以将每个 DoorType 添加到您的标准列表中。
standardList.Add(doorType); // make sure the doorType object and doorType.DoorTypes exists.
// refer to any items
standardList[0].DoorTypes[x]
只是一种方式。
推荐阅读
- laravel - 我如何才能像 Laravel 中的 dd() 函数一样将变量数据作为字符串获取?
- authentication - Keycloak 是否支持某种形式的中间人身份验证?
- java - CloudSDK 能否帮助使用仅在运行时才知道的 OData 实体类型?
- javascript - ChartJS 根据日期更改显示的数据?
- visual-studio - 如何使用新项目格式将文件夹的文件标记为带有通配符的嵌入式资源?
- ios - 如何让 AKSequencer 切换声音字体?
- html - 为什么我的 CSS 规则没有按预期应用?
- java - 在 or-tools 中为 MIP 编写线性表达式
- c# - Unity - 如何掩盖精灵网格内的精灵?
- db2 - 如何通过 LotusScript 从 Lotus Notes Client 连接到 DB2?