[英]How to check if two strings length are equal in c#?
我是c#和unity的新手,想知道如何編寫此代碼來檢查兩個字符串長度是否相等。
具有此代碼統一系統的代碼將顯示此錯誤:錯誤CS1061: char' does not contain a definition for
類型char' does not contain a definition for
Length' char' does not contain a definition for
並且找不到char' Length' of type
擴展方法Length' of type
。
for (int i = 0; i < Answers.Length; i++)
{
if (GetAnswer[i].Length == Answers[i].Length)
{
//Do something
}
}
if (yourString.Length == yourOtherString.Length)
{
//dosomething
}
應該檢查一個字符串的長度是否與另一個字符串相等。代碼的問題是,字符串是char數組,因此它計算char的長度(不存在)
for (int i = 0; i < Answers.Length+1; i++)
{
if (GetAnswer.Length == Answers.Length)
{
//Do something
}
}
您還需要增加for的值以獲取正確的長度,否則Answers.Length始終小於1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.