我正在研究过去几年由各种程序员编辑过的应用程序,我偶然发现了使用String Literals访问MenuItems的问题.
例如:在很多地方都有类似的代码
mainMenu.MenuItems[1].MenuItems[0].Visible=true;
Run Code Online (Sandbox Code Playgroud)
要么
mainMenu.MenuItems["View"].MenuItems["FullScreen"].Visible=true;
Run Code Online (Sandbox Code Playgroud)
如何更改用于标识MenuItem的字符串并捕获它用于访问的所有位置?菜单和菜单项被声明为公共,并在整个大型应用程序中使用
什么是防止使用这些魔术索引的正确方法.每次添加新项目或更改名称时,我都认为有些事情被破坏了.
PS我已经开始使用枚举字典方法,其中每个menuItem都与一个键配对.但这仍然不会迫使其他开发人员使用我的实现,也不是问题2的最优雅的解决方案
我正在编写一个函数来返回一个减去第三个值的列表.这是我目前的代码:
let listString = [ "1"; "2"; "3"; "4" ];;
let del3 (listA :'a) = [listA.Head; listA.Tail.Head] @ [listA.Tail.Tail.Tail];;
del3 listString
Run Code Online (Sandbox Code Playgroud)
我收到错误:
根据此程序点之前的信息查找不确定类型的对象.在此程序点之前可能需要类型注释来约束对象的类型.这可以允许解析查找.
我应该更改什么来修复错误?
我正在尝试使用以下代码:
String MainDB = ConfigurationManager.AppSettings["MainDB"];
MessageBox.Show(MainDB);
String MailInfo = ConfigurationManager.AppSettings["MailInfo"];
MessageBox.Show(MailInfo);
String HousingIndexLocation = ConfigurationManager.AppSettings["HousingIndex"];
MessageBox.Show(HousingIndexLocation);
Run Code Online (Sandbox Code Playgroud)
访问此屏幕生成的值:

每次返回的值都为null。
在这些设置的实现中我缺少什么?
我的代码:
var isSomethingChecked = (document.getElementByName("koalaCheck").checked ||
document.getElementByName("kangarooCheck").checked);
Run Code Online (Sandbox Code Playgroud)
为什么这段代码会抛出一个名为"Type Error"的异常?
我试图在几个不同的类中私下使用一个接口.但是我不会让我在下面看到的getter中调用函数:
public abstract class PreFabComponent : IAccountable
{
//This represents the cumulative cost of all members, connectors, and supporting hardware
private double materialsCost;
protected double MaterialsCost
{
get
{
materialsCost = CalculateSelfCost();
return materialsCost;
}
}
// Returns the sum of all Cumulative costs
double IAccountable.CalculateSelfCost()
{
double sum = 0;
foreach (IAccountable item in accountableItemsContatined)
{
sum += item.CalculateSelfCost();
}
return sum;
}
}
Run Code Online (Sandbox Code Playgroud)
这是界面
interface IAccountable
{
double CalculateSelfCost();
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
我有一张excel表,看起来像这样:

不要问我这是怎么发生的,但不知何故应该是列的东西在这张表中作为行......
你可以看到重复的帐号和列c中的单词,想象一切旋转180度.并为该特定帐号不存在的字段插入空格或空值.
简而言之,它应该看起来像这样:

我无法想到在excel中执行此操作的简单方法.但也许有一些VBA代码?
什么是最简单的解决方案?以及如何实施它?
我知道这个问题不是很清楚,但如果你留下一些指导意见,我很乐意编辑这个问题,直到它有意义.谢谢!
我正在调用一种删除包含特定值的对象的方法.它看起来像这样:
static public void RemovePiece(string BoardId)
{
LumberPiece board = LocateBoard(BoardId);
board = null;
}
Run Code Online (Sandbox Code Playgroud)
LumberPiece是一个看起来像这样的类:
private class LumberPiece
{
public string boardID;
...
}
Run Code Online (Sandbox Code Playgroud)
和LocateBoard是一个返回正确识别的LumberPiece对象的函数:
static private LumberPiece LocateBoard(string BoardId)
{
if (SawyerArea.lumber.boardID == BoardId)
return SawyerArea.lumber;
else if (SpliceArea1.lumber.boardID == BoardId)
return SpliceArea1.lumber;
else if (SpliceArea2.lumber.boardID == BoardId)
return SpliceArea2.lumber;
else
throw new Exception("Your LumberID was not found in any activity area. Has it already been removed? or are you handling the integer-String Conversion Correctly");
}
Run Code Online (Sandbox Code Playgroud)
Area变量是此类的实例:
private …Run Code Online (Sandbox Code Playgroud) 我有一个函数,它接受一个int和一个int列表.它返回一个小于第一个参数的int列表.
我想要复制相同的代码而不使用List.Filter:
let less e L =
L |> List.filter(fun a -> a < e)
less 3 [1;2;4;5]
Run Code Online (Sandbox Code Playgroud)
我想学习递归思考,好像我是用SML编写的
我怎么递归写这个?
我已经创建了一个自定义类型,并希望创建2个变量,以证明我的类型按预期工作.
type number = A of int | B of float;;
let a = 0;;
let b = 0.0;;
Run Code Online (Sandbox Code Playgroud)
我该如何更改变量声明以强制它们输入number?目前a为int,b为float.