Reputation: 563
First of all i'm novice to C#. How to determine array size in C# ? with the if condition check.
Normally php do like this,
if((sizeof($NewArray)==3) && (strtolower($NewArray[1])=='dddd'))
I just tried it out like this,
If(NewArray.Length)==3) && (
After that i'm stucking ....
Upvotes: 0
Views: 262
Reputation: 1948
//in php
if((sizeof($NewArray)==3) && (strtolower($NewArray[1])=='dddd'))
//in C#
if ((NewArray.Length == 3) && (NewArray[1].ToLower() == "dddd"))
Upvotes: 1
Reputation: 64467
I'm not sure what part you are stuck with so I shall explain all the parts I think I can see.
It looks like you are looking for the indexer syntax on arrays.
The code you may want is:
if (NewArray.Length == 3 && NewArray[1].ToLower() == "dddd")
Note the square brackets [] indexing into the array. Regular C# arrays exposes an int
indexer. Once indexed, the dot-notation will give you access to the type inside the array, here I assume that the array is a string[]
, hence we can do NewArray[1].<string members here>
.
Note also that array indexing in C# is zero-based, so 0 is the first element of the array and NewArray.Length - 1
is the last element. Your [1]
may not be correct unless of course you intend on accessing the second array item.
As a side note, using ToLower
is not the only way to get case-insensitive comparisons, you can also do the following:
string.Compare(NewArray[1], "dddd", true) == 0
The string.Compare
documentation shows the ignoreCase
argument. I'm not in any way trying to say my suggestion is best practice.
Upvotes: 2
Reputation: 5023
You're looking for ToLower()
method?
if (newArray.Length == 3 && newArray[1].ToLower() == "dddd") ...
Upvotes: 3
Reputation: 13150
Try this
if( NewArray.Length== 3 && NewArray[1].ToLower() =="dddd")
Upvotes: 0