CS0165 C#使用未分配的局部变量 [英] CS0165 C# Use of unassigned local variable

查看:287
本文介绍了CS0165 C#使用未分配的局部变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将其他任何变量发送给计算类,总计为0.

I'm sending a variable to a calculation class anything else I try I get 0 for total.


      私有静态double Income()
       {
           //声明变量

        private static double Income()
        {
            // declaring varibles

推荐答案

编译器不能确定"while"是循环将永远被执行,因此收入"可能永远不会获得价值.

The compiler can't be certain that the "while" loop will ever be executed, so "income" might never get a value.

要解决此问题,请给收入"声明时为默认值.

To fix it, give "income" a default value when you declare it.

        private static double Income()
        {
            // declaring varibles
            string inputIncome;
            double income = 0.0;  // Give it a value here.


这篇关于CS0165 C#使用未分配的局部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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