文字列を含むオブジェクトの配列があります。
var values = new object[5];
values[0] = "PIZZA HUT";
values[1] = "ISLAMABAD";
values[2] = "ISLAMABAD";
values[3] = "PAKISTAN";
values[4] = "PAKISTAN";
配列から一意の要素の文字列を取得したいのですが、結合して,
、文字列が isNullOrWhiteSpace かどうかも確認する必要があります。
PIZZA HUT, ISLAMABAD, PAKISTAN.
現在、私は次のことを行っています。しかし、if ステートメントで多くのチェックが必要であることがわかります。LINQを使用するより良い方法があるかどうか疑問に思っていました
string featureName = values[0] as string;
string adminboundry4 = values[1] as string;
string adminboundry3 = values[2] as string;
string adminboundry2 = values[3] as string;
string adminboundry1 = values[4] as string;
if (!string.IsNullOrWhiteSpace(adminboundry4)
&& adminboundry4 != adminboundry1
&& adminboundry4 != adminboundry2
&& adminboundry4 != adminboundry3) //want to get rid of these checks
featureName += "," + adminboundry4;
if (!string.IsNullOrWhiteSpace(adminboundry3)) //Not checking for duplicate here just for this question
featureName += "," + adminboundry3;
if (!string.IsNullOrWhiteSpace(adminboundry2)) //Not checking for duplicate here just for this question
featureName += "," + adminboundry2;
if (!string.IsNullOrWhiteSpace(adminboundry1)) //Not checking for duplicate here just for this question
featureName += "," + adminboundry1;
featureName
含むPIZZA HUT, ISLAMABAD, PAKISTAN, PAKISTAN