我一直收到以下代码的错误:
Dictionary<string, string> rct3Features = new Dictionary<string, string>();
Dictionary<string, string> rct4Features = new Dictionary<string, string>();
foreach (string line in rct3Lines)
{
string[] items = line.Split(new String[] { " " }, 2, StringSplitOptions.None);
rct3Features.Add(items[0], items[1]);
////To print out the dictionary (to see if it works)
//foreach (KeyValuePair<string, string> item in rct3Features)
//{
// Console.WriteLine(item.Key + " " + item.Value);
//}
}
Run Code Online (Sandbox Code Playgroud)
错误抛出一句ArgumentException谚语,
"已经添加了具有相同键的项目."
我不确定几个谷歌搜索如何解决这个问题.
稍后在代码中我需要访问字典以获得比较函数:
Compare4To3(rct4Features, rct3Features);
public static void Compare4To3(Dictionary<string, string> dictionaryOne, Dictionary<string, string> dictionaryTwo)
{
//foreach (string …Run Code Online (Sandbox Code Playgroud) 我有这个与我合作的代码.它需要比较字典中的键.如果键匹配则需要比较值以查看它们是否相同,如果不是,我需要将键与两个描述一起写入(第一个字典的值和第二个字典的值).我读过有关TryGetValue的内容,但它似乎并不是我需要的.有没有办法从第二个字典中检索具有与第一个字典中相同的键的值?
谢谢
foreach (KeyValuePair<string, string> item in dictionaryOne)
{
if (dictionaryTwo.ContainsKey(item.Key))
{
//Compare values
//if values differ
//Write codes and strings in format
//"Code: " + code + "RCT3 Description: " + rct3Description + "RCT4 Description: " + rct4Description
if (!dictionaryTwo.ContainsValue(item.Value))
{
inBoth.Add("Code: " + item.Key + " RCT3 Description: " + item.Value + " RCT4 Description: " + );
}
}
else
{
//If key doesn't exist
//Write code and string in same format as input file to array …Run Code Online (Sandbox Code Playgroud) 在尝试创建使用动态端口而不是硬编码端口值的应用程序时,我遇到了以下错误:
System.InvalidOperationException:合同类型 MLITS.Pulse.Pulse 不属于 ServiceContractAttribute。为了定义有效的契约,指定的类型(契约接口或服务类)必须使用 ServiceContractAttribute 进行属性化。
我有问题的代码如下:
public static void DynamicAddress()
{
int sessionIdentification = 0;
int portNumber = 0;
int newPort = 0;
string uriString = string.Empty;
sessionIdentification = Process.GetCurrentProcess().SessionId;
portNumber = 14613;
newPort = portNumber + sessionIdentification;
uriString = "net.tcp://localhost:" + newPort + "/PulseService";
Uri uri = new Uri(uriString);
//ServiceHost objServiceHost = new ServiceHost(typeof(Pulse), uri);
ServiceHost objServiceHost = new ServiceHost(typeof(Pulse));
objServiceHost.Description.Endpoints.Clear();
objServiceHost.AddServiceEndpoint(typeof(Pulse), new NetTcpBinding(), uri);
}
Run Code Online (Sandbox Code Playgroud)
注释掉的部分是我之前的;但是,我意识到我需要清除配置文件中设置的端点;这就是为什么后面的代码存在,以及我遇到麻烦的原因。配置文件的原因在这里解释,在我发布的另一个问题中,以帮助解决我之前遇到的问题。一旦我找到解决方案,我将在两个问题上发布我的结果并关闭它们。
有谁知道我做错了什么,并知道如何解决我收到的错误?
我正在使用 log4Net 从应用程序捕获事务数据,以帮助基本上调试问题/错误。最近,当文件大小达到10MB后,它不再创建新文件,只是停止记录数据。我上网查了一下,发现有消息说我需要添加一个 MutexLock,所以我就这么做了,但没有任何改变。我的附加程序和根级别部分如下:
<!-- Appenders section -->
<log4net>
<appender name="file" type="log4net.Appender.RollingFileAppender">
<file value="c:\programs\DocIt\production\documakerError.log"/>
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d{yyyy-MM-dd HH:mm:ss.fff} [%thread] %-5p %c - %m%n" />
</layout>
<lockingModel type="log4net.Appender.FileAppender+MutexLock" />
</appender>
<!-- root section -->
<root>
<level value="DEBUG"/>
<appender-ref ref="file" />
</root>
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助。
我有一个充满状态及其缩写的关联数组.我正在尝试使用关联php数组的关键字段填充下拉列表.但是,当我试图将字段放在他们<option>的标签内时,我遇到了一些障碍.这就是我所拥有的(减去关联数组).
<body>
<select>
<?php
foreach ($states as $key => $value) {
echo "<option value="\ . $key . ">" . $key . "</option><br/>"; //Prints out the Abbreviation of the states
}
?>
</select>
</body>
Run Code Online (Sandbox Code Playgroud)
我相信我的逃脱顺序是正确的.我正在尝试将密钥作为HTML标记的值.我没有使用MySQL,只是我创建的一个关联数组,我在网上找到的很多资源由于他们使用MySQL而无法遵循.
我知道我缺少的是非常简单的,只是无法确定它.谢谢你的帮助.