我希望用户选择以下其中一项:l,m,c或a。如果用户输入任何其他输入,它将告诉他们“无效输入”并要求他们再次输入。如果用户输入无效输入,我在尝试让它循环回来时遇到问题。我想我需要使用while循环,但我不确定。
public partial class MainWindow : Window
{
string connectionString;
public MainWindow()
{
InitializeComponent();
connectionString = ConfigurationManager.ConnectionStrings["data_here"].ConnectionString;
}
答案 0 :(得分:0)
使用select
循环(使用case
语句来减少一些冗长)。 (将==
与[ ... ]
一起使用会告诉我您正在使用bash
):
IFS= read -r -p "Enter the file name: " file
numlines=$(wc -l < "$file")
numwords=$(wc -w < "$file")
numchars=$(wc -c < "$file")
select variable in l m c a; do
case $variable in
l) echo "The file $file has $numlines lines"
;;
m) echo "The file $file has $numwords words"
;;
c) echo "The file $file has $numchars characters"
;;
a) echo "The file $file has $numlines lines"
echo "The file $file has $numwords words"
echo "The file $file has $numchars characters"
;;
*) echo "Invalid input"
;;
esac
done