多字符串切换语句 [英] Multiple String Switch Statement

查看:62
本文介绍了多字符串切换语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多字符串,我想通过switch语句运行。这些字符串是诸如无之类的术语。或者未定义,我想设置为Null。我的第一个想法是创建一个数组,然后使用foreach语句通过switch语句运行每个字符串。这里显而易见的问题是你不能分配给迭代变量。我怎样才能解决这个问题?

I have numerous strings that I would like to run though a switch statement. These strings are terms such as "None" or "Undefined", that I would like to set to Null. My first thought was to create an array and then use a foreach statement to run each string through the switch statement. The obvious problem here is that you cannot assign to the iteration variables. How can I get around this?

推荐答案

您可以创建这些字符串值的集合并遍历集合并分配给它们。
You could make a collection of those string values and iterate through the collection and assign to each of them.



您可以创建这些字符串值的集合并遍历集合并分配给它们。
You could make a collection of those string values and iterate through the collection and assign to each of them.



我想我不明白如何解决分配给字符串的问题。

I suppose I do not understand how that solves the problem of assigning to the strings.



我有很多字符串,我想通过switch语句运行。这些字符串是诸如无之类的术语。或者未定义,我想设置为Null。我的第一个想法是创建一个数组,然后使用foreach语句通过switch语句运行每个字符串。这里显而易见的问题是你不能分配给迭代变量。我怎么能绕过这个?
I have numerous strings that I would like to run though a switch statement. These strings are terms such as "None" or "Undefined", that I would like to set to Null. My first thought was to create an array and then use a foreach statement to run each string through the switch statement. The obvious problem here is that you cannot assign to the iteration variables. How can I get around this?



创建一个列表/数组,但使用for循环而不是foreach。然后你就可以为你的字符串赋值了。

Create a list/array but use a for loop instead of a foreach. Then you will be able to assign values to your strings.

展开 | 选择 | Wrap | 行号


这篇关于多字符串切换语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆