您可以指定一个整数值,并在循环中为每次迭代加 1。当它等于 1 时,您将初始值设置为 myQuery 字符串。
示例代码如下:
static void Main(string[] args)
{
CloudStorageAccount storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("your_account", "your_key"),true);
// Create the table client.
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
// Create the CloudTable object that represents the "people" table.
CloudTable table = tableClient.GetTableReference("people");
string myQuery = string.Empty;
List<string> myConditionLists = new List<string>();
myConditionLists.Add("Ben1");
myConditionLists.Add("Ben2");
myConditionLists.Add("Ben3");
myConditionLists.Add("Ben4");
myConditionLists.Add("Ben5");
//specify an integer value
int i = 0;
foreach (string myCondition in myConditionLists)
{
i++;
//if i == 1, specify the initial value to the myQuery string.
if (i == 1) { myQuery = TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition); }
else
{
myQuery = TableQuery.CombineFilters(
myQuery,
TableOperators.And,
TableQuery.GenerateFilterCondition("RowKey", QueryComparisons.NotEqual, myCondition)
);
}
}
TableQuery<CustomerEntity> query = new TableQuery<CustomerEntity>().Where(myQuery);
foreach (CustomerEntity entity in table.ExecuteQuery(query))
{
Console.WriteLine("{0}, {1}\t{2}\t{3}", entity.PartitionKey, entity.RowKey,
entity.Email, entity.PhoneNumber);
}
Console.WriteLine("---completed---");
Console.ReadLine();
}
我的桌子:
测试结果: