我试图返回到主程序,但它必须在ComboBox更改时更改。无论它返回的是什么,无论在类的顶部将字符串设置为什么。如果我将% the result = "";更改为% result = "Test";,它将在我试图更新的TextBox中显示Test。但是它不会从IF语句中得到任何东西。
谢谢你的帮助!
主程序
namespace VTCPT
{
/// <summary>
///
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//UPDATE THE SHORTCODE TEXTBLOCK
updateVTCShortCode display = new updateVTCShortCode();
display.mergeShortCode(longFormCodec.SelectedItem.ToString());
if (String.IsNullOrEmpty(display.finalResult()))
{ shortFormCodec.Text = ".."; }
else { shortFormCodec.Text = display.finalResult(); }
}
private void updateShortForm(object sender, SelectionChangedEventArgs e)
{
}
private void TextBlock_SelectionChanged(object sender, RoutedEventArgs e)
{
}
private void fsSiteBuild_SelectionChanged(object sender, RoutedEventArgs e)
{
}
private void updateSiteBuild(object sender, TextChangedEventArgs e)
{
int index = fsRoomDesig.Text.IndexOf(".");
if (index > 0)
{ fsSiteBuild.Text = fsRoomDesig.Text.Substring(0, index); }
else { fsSiteBuild.Text = ".."; }
}
private void vtcSystemName_SelectionChanged(object sender, RoutedEventArgs e)
{
}
}
}updateVTCShortCode类
namespace VTCPT
{
class updateVTCShortCode
{
String result = ""; //////ALWAYS RESULTS ONLY IN WHAT IS HERE
public void mergeShortCode(String longFormCodec)
{
if (longFormCodec == "Cisco SX80")
{
String sendShortForm = "SX80";
result = "V-T" + sendShortForm;
}
if (longFormCodec == "Cisco Webex Codec Plus")
{
String sendShortForm = "SRK";
result = "V-T" + sendShortForm;
}
if (longFormCodec == "Cisco Webex Codec Pro")
{
String sendShortForm = "SRK";
result = "V-T" + sendShortForm;
}
}
public String finalResult()
{ return result; }
}
}发布于 2020-06-18 10:19:03
您没有正确地进行字符串比较。对于字符串,您需要使用.equals()。
您需要将使用==的所有字符串比较替换为.equals(),它将起作用:
namespace VTCPT
{
class updateVTCShortCode
{
String result = ""; //////ALWAYS RESULTS ONLY IN WHAT IS HERE
public void mergeShortCode(String longFormCodec)
{
if (longFormCodec.equals("Cisco SX80"))
{
String sendShortForm = "SX80";
result = "V-T" + sendShortForm;
}
if (longFormCodec.equals("Cisco Webex Codec Plus"))
{
String sendShortForm = "SRK";
result = "V-T" + sendShortForm;
}
if (longFormCodec.equals("Cisco Webex Codec Pro"))
{
String sendShortForm = "SRK";
result = "V-T" + sendShortForm;
}
}
public String finalResult()
{ return result; }
}
}https://stackoverflow.com/questions/62441260
复制相似问题