如何使用12个单元格和2个模式的if语句 [英] How can I use if statment for 12 cells and 2 modes
本文介绍了如何使用12个单元格和2个模式的if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我有12个单元格和两种模式。
例如:
Hallo,
I have 12 cells and two modes.
For example:
if (comboBox5.SelectedItem == "Cell_1" && comboBox4.SelectedItem == "Mode_1")
{
xmlWriter.WriteStartElement("Cell_1");
xmlWriter.WriteStartElement("Amplitude");
xmlWriter.WriteString(textBox17.Text);
//xmlWriter.WriteString(textBox7.Text);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("Frequency");
xmlWriter.WriteString(textBox18.Text);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("Duration");
xmlWriter.WriteString(textBox19.Text);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement(); //::::::::::::::
}
else if (comboBox4.SelectedItem == "Mode_2")
{
xmlWriter.WriteStartElement("Amplitude");
xmlWriter.WriteString(textBox17.Text);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("Duration");
xmlWriter.WriteString(textBox18.Text);
xmlWriter.WriteEndElement();
}
我必须检查12个单元格,只有当我在我的组合框4中选择Mode_2时它才会改变。
喜欢
cell_1,mode_1:
cell_2,mode_2:
或随机cell_2,mode_2 .... %%当我选择模式2时:第二个操作有以振幅和持续时间执行...
请使用代码帮助..
谢谢。
我尝试过:
尝试使用if语句,如果我检查所有12:2的情况,它将是非常长的代码。
I have to check for 12 cells it should change only if i select Mode_2 in my combobox4.
Like
cell_1, mode_1:
cell_2,mode_2 :
or random cell_2,mode_2.... %%when i select mode 2: second operation has to perform with amplitude and duration...
PLease help with the code..
Thank you.
What I have tried:
tried using if statement it will be very long code if i check for all 12:2 cases.
推荐答案
这将需要一些研究,但这种也可以使用序列化
来完成。
这样你就可以使用一个使编码更容易的类,并序列化类或列表<>
到XML
。
请参阅: [如何使用Visual C#将对象序列化为XML#]
使用示例a<>:
It will take some study, but this kind of thing can be done also usingserialization
.
This way you can work with a class which makes coding a lot easier, and serialize the class orList<>
toXML
.
See: [How to serialize an object to XML by using Visual C#]
An example using a List<>:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
public class Program
{
public static void Main()
{
// Test list with classes.
List<classElement1> listStr = new List<classElement1>();
listStr.Add(new classElement1() { Check = true, Group = "GroupOne" });
listStr.Add(new classElement1() { Check = false, Group = "GroupTwo" });
var x = new XmlSerializer(listStr.GetType());
x.Serialize(Console.Out, listStr);
using (var strWriter = new StringWriter())
{
x.Serialize(strWriter, listStr);
File.WriteAllText("test.xml", strWriter.ToString());
}
Debug.Print("Test Serialization done !");
}
public class classElement1
{
public bool Check;
public string Group = "no group";
public string Key = "no key";
public string Value { get; set; }
}
}
这篇关于如何使用12个单元格和2个模式的if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!