我现在想要改变这一点,以便用户可以选择记录哪些变量而不是硬编码变量。因此,用户可以输入字段列表作为逗号分隔字段,例如MyUser.userId,MyTransSeq.transactionId,MyVarValueDict,并将其写入array2。 array2的内容现在包含: [0] =MyUser.userId, [1] =MyTransSeq.transactionId, [2] =MyVarValueDict 问题是它们现在是引号中的文本值。所以我的问题是如何将文本数组值(如MyUser.userId)重新转换为对象。以下是我尝试过的一些代码没有成功?Output from above code2015-01-29 21:20:57.935 +00:00 [Information] User name: "pclarkeirl" Transaction: "initmenu01" Transaction values: [("<&option>": " "), ("<&envname>": "\" \""), ("<&test>": "MYTESTVALU"), ("<&envcount>": "3"), ("<&companyid>": "strykerlmk"), ("<&envdesc1>": " "), ("<&envdesc2>": " "), ("<&envcolour>": " "), ("<&count>": " "), ("<&selopt>": " ")]I now want to change this so that rather than hard code the variables, the user can select which variables are to be logged. So the user can type in the list of fields as a comma delimited field such as "MyUser.userId, MyTransSeq.transactionId, MyVarValueDict" and this is written to array2. The contents of array2 now contain:[0]="MyUser.userId",[1]="MyTransSeq.transactionId",[2]="MyVarValueDict"The problem is that they are now Text values in quotes. So my question is How can I turn a text array value such as "MyUser.userId" back into an object. Below is some code I have tried without success ?string[] userSelArray={"MyUser.userId", "MyTransSeq.thisTransId", "MyVarValuesDict" }; // This is simulating the array values received from user.string[] array1 = { "User name:", "Transaction:", "Transaction values:" };object[] array2 = new object[array1.Count()];string text = "";for (int j = 0; j < array1.Length; j++){ text = text + array1[j] + " {" + j + "} "; array2[j] = userSelArray[j];}MyGlobals.logger.Information("NEXT" + text, array2.ToArray()); 以上代码输出 2015-01-29 22:01:44.502 +00:00 [信息] NEXTUser名称:MyUser.userId交易:MyTransSeq。 thisTransId交易价值:MyVarValuesDict 上面你可以看到变量名称被视为文本并且没有被翻译推荐答案 C#是面向对象的。您需要创建表示问题/应用程序中的事物的类。变量包含属性/值,并且方法使您能够访问和操作变量。 您对每个值进行硬编码。您需要设计程序以适用于所有情况。C# is object-oriented. You need to create classes representing the things in your problem/application. The variables hold the attributes/values and the methods enable you to access and manipulate the variables.You are hard-coding every value. You need to design the program to work for all cases.我很难对此进行编码以仅提供示例。所以也许专注于提供问题的答案 问候 PatI am hard coding this to provide an example only. So maybe concentrate on providing an answer to the questionregardsPat 这篇关于如何将文本数组元素转换为对象数组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-27 06:14
查看更多