Не выводятся аргументы консольного приложения в области "Аргументы приложения" Visual Studio
Не могу вывести аргументы в конколь из области "Аргументы приложения". В интернете говорят, что это может быть из-за разных установленных платформ, но я в своём проекте изменять их даже не могу. Создал даже новый проект, перекинул туда код, но ничего не изменилось. Всё та же проблема.
Я только изучаю C# и не имею ни малейшего представления, что ни так. Что-то в моём коде или в настройках Visual Studio?
using System;
namespace TestCode
{
class Program
{
static void Main(string[] args)
{
string savePassword = "password12";
string login = GetString("Enter your login:");
string password = GetString("Enter password: ");
if (password == savePassword)
{
OutLineResult("", $"{login} enter the System");
}
else
{
byte attempt = 1;
do
{
OutLineError($"Wrong password. You have {3 - attempt} more attempts left");
password = GetString("Enter password: ");
attempt++;
if (password == savePassword)
{
OutLineResult("", $"{login} enter the System");
break;
}
} while (attempt < 3);
Console.WriteLine(attempt);
if (attempt >= 3)
{
OutLineError("\nThe number of available tries have been exceeded");
}
}
}
static string GetString(string text)
{
Console.WriteLine(text);
Console.ForegroundColor = Console.ForegroundColor = ConsoleColor.Yellow;
string s = Console.ReadLine();
Console.ForegroundColor = ConsoleColor.Gray;
return s;
}
static int GetInt(string text)
{
Console.WriteLine(text);
Console.ForegroundColor = Console.ForegroundColor = ConsoleColor.Yellow;
int i = int.Parse(Console.ReadLine());
Console.ForegroundColor = ConsoleColor.Gray;
return i;
}
static int GetUInt(string text)
{
int d;
do
{
Console.Write(text);
Console.ForegroundColor = Console.ForegroundColor = ConsoleColor.Yellow;
d = int.Parse(Console.ReadLine());
Console.ForegroundColor = ConsoleColor.Gray;
if (d < 0)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("The number of digits cannot be negative\n");
Console.ForegroundColor = ConsoleColor.Gray;
}
}
while (d < 0);
return d;
}
static double GetDouble(string text)
{
Console.WriteLine(text);
Console.ForegroundColor = Console.ForegroundColor = ConsoleColor.Yellow;
double d = double.Parse(Console.ReadLine());
Console.ForegroundColor = ConsoleColor.Gray;
return d;
}
static void OutLineResult(string text, string result)
{
Console.Write(text);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(result);
Console.ForegroundColor = ConsoleColor.Gray;
}
static void OutLineError(string text)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(text);
Console.ForegroundColor = ConsoleColor.Gray;
}
}
}
Ответы (1 шт):
Автор решения: kva52
→ Ссылка
args это массив строковых параметров, которые ваша программа получает на входе. Типа при запуске из консоли:
c:\> TestCode аргумент0 аргумент1
Если же запускаете из VS (при отладке), то строки аргументов берутся из области "Аргументы приложения". А в программе вы должны проверить типа:
if (args.Length > 0)
{
if (args[0]=="аргумент0")
{....}
}
