不等于字符串

时间:2013-05-09 08:22:10

标签: c# string

我试图设置这样的条件

    if (myString=!"-1")
{
//Do things
}

但它失败了。我试过了

if(myString.Distinct("-1")) 
    {
    //Do things
    }

但它也不起作用。

4 个答案:

答案 0 :(得分:15)

试试这个:

if(myString != "-1")

opperand是!=而不是=!

您也可以使用Equals

if(!myString.Equals("-1"))

请注意myString

之前的!

答案 1 :(得分:14)

应该是这样的:

if (myString!="-1")
{
//Do things
}

你的平等和感叹是错误的方式。

答案 2 :(得分:0)

现在在 C# 9 中,它可以像这样以更具可读性的方式完成。

string  str = "x";
if(str is not "y")
{
    ...
}

答案 3 :(得分:-1)

通过class StoreTotalPanel : RelativeLayout { @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : super(context, attrs, defStyleAttr) @TargetApi(Build.VERSION_CODES.LOLLIPOP) constructor( context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) init { LayoutInflater.from(context) .inflate(layout.panel_store_total, this, true) attrs?.let { // <- Here is error val typedArray = context.obtainStyledAttributes(it, R.styleable.custom_card_view) val myString = typedArray.getString(R.styleable.custom_card_view_command) } } ... } ,您还可以使用similar question

Equals()
相关问题