具有默认值的全局声明 [英] global declarations with the default value

查看:66
本文介绍了具有默认值的全局声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;

namespace PrintPrice
{
    class Price
    {
        const int pricePerLicense = 10;

        static void Main()
        {
            int pricePerLicense;
            Console.Write("Enter a price for license: ");
            pricePerLicense = int.Parse(Console.ReadLine()); 
            Console.Write("price for license: " + pricePerLicense);
            Console.ReadKey();
        }
    }
}


如果仅按Enter键而不输入值,请使用默认值或常数值
请帮我谢谢


If you press only ENTER without entering a value, use a default or the constant value
pleas help me thanks

推荐答案

您可以在c#.net中使用全局变量
使用具有公共访问权限madifire的类并为其分配默认值.
C#全局变量 [
You can use global variable in c#.net
use a class with public access madifires and assign default value to it.
C# Global Variable[^]


using System;

namespace PrintPrice
{
	class Price
	{
		public const int pricePerLicense = 10;

		static void Main()
		{
			int pricePerLicense;
			Console.Write("Enter a price for license: ");
			if (!int.TryParse(Console.ReadLine(), out pricePerLicense))
				pricePerLicense = Price.pricePerLicense;
			Console.Write("price for license: " + pricePerLicense);
			Console.ReadKey();
		}
	}
}


这篇关于具有默认值的全局声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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