Convert.ToDouble作用

Convert.ToDouble是将一个String类型强制转换为Double型,在屏幕中输入的文字是字符,需要强制转化为double类型。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ch03Ex02
{
    class Program
    {
        static void Main(string[] args)
        {
            double firstNumber, secondNumber;
            string useName;
            Console.WriteLine("Enter your name:");
            useName = Console.ReadLine();
            Console.WriteLine($"Welcome {useName}");
            Console.WriteLine($"Now give me a number:");
            firstNumber = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine($"Now give me another number:");
            secondNumber = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine($"The sum of {firstNumber}+{secondNumber} is"+$"{firstNumber+secondNumber}.");
            Console.WriteLine($"The result  of subtracting {secondNumber}from"+$"{firstNumber}is{firstNumber-secondNumber}");
            Console.WriteLine($"The product of {firstNumber}and {secondNumber}is" + $"{firstNumber*secondNumber}");
            Console.WriteLine($"The result of dividing {firstNumber}by" + $"{secondNumber }is{firstNumber/secondNumber}");
            Console.WriteLine($"The remainder after dividing{firstNumber}by" + $"{secondNumber}is{firstNumber%secondNumber}");
            Console.ReadKey();
        }
    }
}
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Java中可以使用的操作符包括lambda表达式、方法引用和构造器引用。 Lambda表达式是一种匿名函数,可以作为参数传递给其他方法或函数式接口。例如,可以使用lambda表达式连接两个函数式接口: ``` Function<Integer, Integer> addOne = x -> x + 1; Function<Integer, Integer> multiplyByTwo = x -> x * 2; Function<Integer, Integer> addOneAndMultiplyByTwo = addOne.andThen(multiplyByTwo); ``` 上面的代码定义了两个函数式接口addOne和multiplyByTwo,然后使用andThen方法连接它们,生成一个新的函数式接口addOneAndMultiplyByTwo,该接口的功能是先加1,然后再乘以2。 方法引用是一种简洁的方式,可以将现有的方法作为函数式接口的实现。例如,可以使用方法引用连接两个函数式接口: ``` Function<String, Integer> parseInt = Integer::parseInt; Function<Integer, Double> convertToDouble = Integer::doubleValue; Function<String, Double> parseAndConvert = parseInt.andThen(convertToDouble); ``` 上面的代码定义了两个函数式接口parseInt和convertToDouble,然后使用andThen方法连接它们,生成一个新的函数式接口parseAndConvert,该接口的功能是先将字符串转换为整数,然后将整数转换为双精度浮点数。 构造器引用是一种简洁的方式,可以将现有的构造器作为函数式接口的实现。例如,可以使用构造器引用连接两个函数式接口: ``` Function<String, Integer> parseInt = Integer::new; Function<Integer, Double> convertToDouble = Double::new; Function<String, Double> parseAndConvert = parseInt.andThen(convertToDouble); ``` 上面的代码定义了两个函数式接口parseInt和convertToDouble,然后使用andThen方法连接它们,生成一个新的函数式接口parseAndConvert,该接口的功能是先将字符串转换为整数,然后将整数转换为双精度浮点数。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值