标签: unassigned-variable

"使用未分配的局部变量"是什么意思?

我一直收到annualRate,monthlyCharge和lateFee的错误.

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

namespace Lab_5___Danny_Curro
{
    class Program
    {
        static void Main(string[] args)
        {
            string firstName;
            string lastName;
            int accNumber;
            string creditPlan;
            double balance;
            string status;
            Boolean late = false;
            double lateFee;
            double monthlyCharge;
            double annualRate;
            double netBalance;


            Console.Write("Enter First Name: ");
            firstName = Console.ReadLine();

            Console.Write("Enter Last Name: ");
            lastName = Console.ReadLine();

            Console.Write("Enter Account Number: ");
            accNumber = Convert.ToInt32(Console.ReadLine());


            Console.Write("Enter Credit Card Plan Number[Blank Will Enter Plan 0]: ");
            creditPlan = Console.ReadLine();

            Console.Write("Enter Balance: …
Run Code Online (Sandbox Code Playgroud)

c# unassigned-variable

30
推荐指数
5
解决办法
19万
查看次数

Delphi:如何确定和清空TDatetime值

似乎没有办法分配NULL(变量的" 未赋值 ")TDateTime.

我想象的唯一方法是使用这样的东西:

function isNull(aDate : TDateTime) : boolean;
const NullDate = 0.0;
var aNullDate : TDatetime;
    ms : Int64;
begin
  aNullDate := NullDate;
  ms := MilliSecondsBetween(aDate,aNullDate);
  result := (ms = Int64(0));
end;
Run Code Online (Sandbox Code Playgroud)

是否有谁知道更好的解决方案什么不重叠0日期值?

负值是TDateTime危险的吗?(作为以前用途的能力资源)

delphi null datetime unassigned-variable

15
推荐指数
2
解决办法
4万
查看次数

c#切换问题

我是编程新手并遇到以下代码问题的新手:

    private string alphaCoords(Int32 x)
    {
        char alphaChar;

        switch (x)
        {
            case 0: alphaChar = 'A'; break;
            case 1: alphaChar = 'B'; break;
            case 2: alphaChar = 'C'; break;
            case 3: alphaChar = 'D'; break;
            case 4: alphaChar = 'E'; break;
            case 5: alphaChar = 'F'; break;
            case 6: alphaChar = 'G'; break;
            case 7: alphaChar = 'H'; break;
            case 8: alphaChar = 'I'; break;
            case 9: alphaChar = 'J'; break;
        }

        return alphaChar.ToString();
    }
Run Code Online (Sandbox Code Playgroud)

编译器说:使用未分配的局部变量'alphaChar'

但我正在我的交换机块中分配它.

我确定这是我的错,因为我对编程知之甚少.

请指教.

谢谢.

c# switch-statement unassigned-variable

8
推荐指数
1
解决办法
4799
查看次数

未分配的非可空变量的值(C#)

只是好奇.

如果你走的话:

string myString;
Run Code Online (Sandbox Code Playgroud)

它的值为null.

但如果你去:

int myInt;
Run Code Online (Sandbox Code Playgroud)

C#中此变量的值是多少?

谢谢

大卫

c# non-nullable unassigned-variable

7
推荐指数
3
解决办法
4953
查看次数

在finally块上使用未分配的局部变量

i在这个例子中什么时候可以取消分配?

int i;
try
{
    i = 2;
}
catch
{
    i = 3;
}
finally
{
    string a = i.ToString();
}
Run Code Online (Sandbox Code Playgroud)

c# try-catch local-variables unassigned-variable

7
推荐指数
1
解决办法
1697
查看次数

C#错误:使用未分配的局部变量

错误是在for循环中引起的:

for (i = 0; i < hand.Length; i++)
{
   Console.WriteLine(hand[i]);
}
Run Code Online (Sandbox Code Playgroud)

我试图存储值,以便以后显示它们.写作线可以帮助我确保代码实际上按照我的意图运行.

其余代码供参考:*编辑:添加了一行代码

enum house //variable type for the card type
{
    Spades, Hearts, Clubs, Diamonds
}

enum cards //variable type for the cards
{
    Joker, Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King
}

class Program
{
    static void Main(string[] args)
    {

        Random rnd;
        Random rnd2;

        int i;
        int random;
        int random2;

        String[] hand;

        house randomhouse;
        cards randomcard;

        //all declared variables

        Console.WriteLine("Your hand …
Run Code Online (Sandbox Code Playgroud)

c# arrays loops unassigned-variable

6
推荐指数
1
解决办法
4693
查看次数

在创建关闭自身的匿名函数时使用未分配的局部变量

为什么这个声明+赋值会导致错误:

// Use of unassigned local variable 'handler'.
SessionEndingEventHandler handler = (sender, e) => { isShuttingDown = true; SystemEvents.SessionEnding -= handler; };
Run Code Online (Sandbox Code Playgroud)

虽然这不是:

SessionEndingEventHandler handler = null;
handler = (sender, e) => { isShuttingDown = true; SystemEvents.SessionEnding -= handler; };
Run Code Online (Sandbox Code Playgroud)

直观地说,第一个语句应该导致错误但不能立即清楚为什么第二个语句不是.

此外,SystemEvents.SessionEnding在调用之后,如何判断事件是否实际上已取消订阅handler(null, null)?该GetInvocationList只适用于委托.

SystemEvents.SessionEnding += handler;
handler(null, null);
Run Code Online (Sandbox Code Playgroud)

.net c# variables delegates unassigned-variable

6
推荐指数
1
解决办法
702
查看次数

使用未分配的局部变量.但总是落入任务

有这个代码,我不明白为什么如果在finally块中分配变量不理解它将始终被分配.我想我错过了一个无法分配货币的有效选项.如果你知道,理解为什么会很棒.非常感谢!

谢谢!

CurrencyVO currency;

try
{
     if (idConnection.HasValue && idConnection != 0)
     {
         currencyConnection = client.GetConnection(idConnection.Value);
         model.Connection = currencyConnection;
     }
     else 
     {
         int providerUserKey = (int)Models.UserModel.GetUser().ProviderUserKey;
         currencyConnection = client.GetConnection(providerUserKey);
     }                        
     currency = model.Currencies.SingleOrDefault(c => c.IdCountry == currencyConnection.idcountry) ?? new CurrencyVO();    
} 
catch
{
      currency = new CurrencyVO();                    
} 
finally
{
      model.PublishedContainer.Currency = currency;
}
Run Code Online (Sandbox Code Playgroud)

finally块上发生错误.如果我把它从finally块中取出来像这样:

                } catch {
                    currency = new CurrencyVO();
                }
                model.PublishedContainer.Currency = currency;
Run Code Online (Sandbox Code Playgroud)

它工作正常.

c# try-catch unassigned-variable

5
推荐指数
1
解决办法
1117
查看次数

错误:使用未分配的局部变量(用于字符串数组)

我正在从我的App.config文件中读取连接字符串,为此我有以下代码.

try
 {
    string[] dbnames;
    int counter = 0;
    foreach (ConnectionStringSettings connSettings in ConfigurationManager.ConnectionStrings) 
    {
        dbnames[counter] = connSettings.Name;
        counter++;
    }
    return dbnames;
 }
 catch
 {
    throw;
 }
Run Code Online (Sandbox Code Playgroud)

这段代码让我错误地使用了未分配的dbnames局部变量.我将在App.config中有多个连接字符串.它们可以是无,1,2等等.根据需要.所以我不能静态分配dbname大小.因为如果超过指定大小的值,可能会出现这种情况.例如.如果我指定它的大小为5,如果我得到第6个连接字符串怎么办?如果我有1,那么剩下的4将是记忆的浪费.

如果我错了,请告诉我.

谢谢.

.net c# arrays unassigned-variable c#-4.0

4
推荐指数
2
解决办法
3万
查看次数

Fortran 未分配数组

我刚开始学习 Fortran,遇到了这个问题。考虑下面的简单代码。

PROGRAM random

INTEGER, DIMENSION(12):: array
PRINT *, array

END PROGRAM random
Run Code Online (Sandbox Code Playgroud)

array未分配的值,但可以打印,它似乎有一些随机的因素和一些零元素。但是,如果我考虑更短的数组,请说我声明

INTEGER, DIMENSION(5):: array
Run Code Online (Sandbox Code Playgroud)

那么打印的数组的所有元素都为 0。我想知道这里发生了什么?

variables fortran unassigned-variable

4
推荐指数
1
解决办法
446
查看次数