在我的 Windows 计算机上,我尝试使用以下 Dockerfile 构建容器化的 Node.js 应用程序:
# use latest version of nodejs
FROM node:lts-alpine
# install aurelia-cli to build the app & http-server to serve static contents
RUN npm i -g http-server
RUN npm i -g aurelia-cli
# set working directory to app
# henceforth all commands will run inside this folder
WORKDIR /app
# copy package.json related files first and install all required dependencies
COPY package*.json ./
RUN npm install
# copy the rest of the files and …
Run Code Online (Sandbox Code Playgroud) 我在具有以下结构的 C# 方法中有一个循环。
do
{
getUserInput();
if (inputIsBad)
{
doSomethingElse();
}
} while (inputIsBad);
Run Code Online (Sandbox Code Playgroud)
或者,使用 while 循环:
getUserInput();
while (inputIsBad)
{
doSomethingElse();
getUserInput();
}
Run Code Online (Sandbox Code Playgroud)
但是这两种方法都使用了冗余代码:do-while 有一个 if 语句和 while 循环检查相同的条件;while 循环在循环之前和内部都调用 getUserInput()。
是否有一种简单的、非冗余的、非临时的方式来完成这些方法模式所做的事情,无论是一般情况下还是在 C# 中,只涉及编写每个基本组件一次?