<small id='A8UfK'></small><noframes id='A8UfK'>

      <legend id='A8UfK'><style id='A8UfK'><dir id='A8UfK'><q id='A8UfK'></q></dir></style></legend>

      <tfoot id='A8UfK'></tfoot>
      • <bdo id='A8UfK'></bdo><ul id='A8UfK'></ul>
    1. <i id='A8UfK'><tr id='A8UfK'><dt id='A8UfK'><q id='A8UfK'><span id='A8UfK'><b id='A8UfK'><form id='A8UfK'><ins id='A8UfK'></ins><ul id='A8UfK'></ul><sub id='A8UfK'></sub></form><legend id='A8UfK'></legend><bdo id='A8UfK'><pre id='A8UfK'><center id='A8UfK'></center></pre></bdo></b><th id='A8UfK'></th></span></q></dt></tr></i><div id='A8UfK'><tfoot id='A8UfK'></tfoot><dl id='A8UfK'><fieldset id='A8UfK'></fieldset></dl></div>
    2. 在 C# 中将 String 转换为 int

      Convert String to int in C#(在 C# 中将 String 转换为 int)
      <tfoot id='R3lyV'></tfoot>

      • <bdo id='R3lyV'></bdo><ul id='R3lyV'></ul>

        <small id='R3lyV'></small><noframes id='R3lyV'>

            <tbody id='R3lyV'></tbody>
          <legend id='R3lyV'><style id='R3lyV'><dir id='R3lyV'><q id='R3lyV'></q></dir></style></legend>
          • <i id='R3lyV'><tr id='R3lyV'><dt id='R3lyV'><q id='R3lyV'><span id='R3lyV'><b id='R3lyV'><form id='R3lyV'><ins id='R3lyV'></ins><ul id='R3lyV'></ul><sub id='R3lyV'></sub></form><legend id='R3lyV'></legend><bdo id='R3lyV'><pre id='R3lyV'><center id='R3lyV'></center></pre></bdo></b><th id='R3lyV'></th></span></q></dt></tr></i><div id='R3lyV'><tfoot id='R3lyV'></tfoot><dl id='R3lyV'><fieldset id='R3lyV'></fieldset></dl></div>

                本文介绍了在 C# 中将 String 转换为 int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试编写一个简单的程序,要求用户输入一个数字,然后我将使用该数字来决定给定年龄的门票费用.尝试将字符串转换为 int 时遇到问题.否则程序布局很好.有什么建议?谢谢

                I am trying to write a simple program that asks the user to enter a number and then I will use that number to decide what the cost of the ticket will be for their given age. I am having trouble when trying to convert the string to int. Otherwise the program layout is fine. Any suggestions? thanks

                using System;
                
                class ticketPrice
                {    
                    public static void Main(String[] args)
                    {
                        Console.WriteLine("Please Enter Your Age");
                        int input = Console.ReadLine();
                        if (input < 5)
                        {
                            Console.WriteLine("You are "+input+" and the admisson is FREE!");
                        }
                        else if (input > 4 & input < 18)
                        {
                            Console.WriteLine("You are "+input+" and the admission is $5");
                        }
                        else if (input > 17 & input < 56)
                        {
                            Console.WriteLine("You are "+input+" and the admission is $10");
                        }
                        else if (input > 55)
                        {
                            Console.WriteLine("You are "+input+" and the admission is $8");
                        }
                    }
                }
                

                推荐答案

                试试 int.TryParse(...) 方法.它不会抛出异常.

                Try the int.TryParse(...) method. It doesn't throw an exception.

                http://msdn.microsoft.com/en-us/library/f02979c7.aspx

                此外,您应该在您的条件中使用 && 而不是 &.&& 是逻辑与,& 是按位与.

                Also, you should use && not & in your conditions. && is logical AND and & is bitwise AND.

                这篇关于在 C# 中将 String 转换为 int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                Accessing attribute info from DTE(从 DTE 访问属性信息)
                c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                C# Attributes and their uses(C# 属性及其用途)
                C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
              1. <legend id='vI5tw'><style id='vI5tw'><dir id='vI5tw'><q id='vI5tw'></q></dir></style></legend>

                <small id='vI5tw'></small><noframes id='vI5tw'>

              2. <i id='vI5tw'><tr id='vI5tw'><dt id='vI5tw'><q id='vI5tw'><span id='vI5tw'><b id='vI5tw'><form id='vI5tw'><ins id='vI5tw'></ins><ul id='vI5tw'></ul><sub id='vI5tw'></sub></form><legend id='vI5tw'></legend><bdo id='vI5tw'><pre id='vI5tw'><center id='vI5tw'></center></pre></bdo></b><th id='vI5tw'></th></span></q></dt></tr></i><div id='vI5tw'><tfoot id='vI5tw'></tfoot><dl id='vI5tw'><fieldset id='vI5tw'></fieldset></dl></div>

                  <tfoot id='vI5tw'></tfoot>
                    <tbody id='vI5tw'></tbody>
                    <bdo id='vI5tw'></bdo><ul id='vI5tw'></ul>