簡體   English   中英

C#元組比較

[英]C# Tuple comparison

最近兩天我一直在努力嘗試以使代碼的這一部分正常工作。

foreach (Tuple<StateObject,string> tupleObj in TCP_Globals.stateObj)
{

    if (tupleObj.Item2.Equals(ConnectedClientsListView.FocusedItem.SubItems[2].Text))
    {
        MessageBox.Show("DEBUG #3");
        StateObject stateObj = tupleObj.Item1; //Obtain the underlying socket management class via remoteIP
        MessageBox.Show("DEBUG #4");
    }
}

那個...

if (tupleObj.Item2.Equals(ConnectedClientsListView.FocusedItem.SubItems[2].Text))

...即使兩個字符串包含相同的值,也不會變為true。 如果永遠不會過去。 如何正確比較元組obj和listViewItem?

這個怎么樣

if (tupleObj.Item2.ToString().ToLower() == 
         ConnectedClientsListView.FocusedItem.SubItems[2].Text.ToLower())

編輯:

因為您說過字符串是IP,所以在這種情況下

var firstip = IPAddress.Parse(first_string);
var secondip = IPAddress.Parse(second_string);

if (firstip.Equals(secondip))
{
    Console.WriteLine("Equal!");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM