Questions tagged [unassigned-variable]

93 questions
50
votes
11 answers

What does "Use of unassigned local variable" mean?

I keep getting this error for annualRate, monthlyCharge, and lateFee. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Lab_5___Danny_Curro { class Program { static void Main(string[]…
Daniel Curro
  • 503
  • 1
  • 4
  • 4
20
votes
5 answers

Delphi: How to determine and empty TDatetime value

Seems there is no way to assign NULL (either an "unassigned value" to TDateTime variables. The only way I've imagined is using something like this: function isNull(aDate : TDateTime) : boolean; const NullDate = 0.0; var aNullDate : TDatetime; ms…
xsubira
  • 474
  • 1
  • 5
  • 14
10
votes
4 answers

Use of unassigned local variable on finally block

When could i in this example be unassigned? int i; try { i = 2; } catch { i = 3; } finally { string a = i.ToString(); }
Diego
  • 16,436
  • 26
  • 84
  • 136
9
votes
6 answers

Value of unassigned non-nullable variable (C#)

Just curious. If you go: string myString; Its value is null. But if you go: int myInt; What is the value of this variable in C#? Thanks David
David
  • 15,750
  • 22
  • 90
  • 150
8
votes
8 answers

c# switch problem

I'm new to programming and having a problem with the following code: private string alphaCoords(Int32 x) { char alphaChar; switch (x) { case 0: alphaChar = 'A'; break; case 1: alphaChar = 'B';…
iTEgg
  • 8,212
  • 20
  • 73
  • 107
6
votes
1 answer

Use of unassigned local variable when creating an anonymous function closing on itself

Why does this declaration+assignment cause an error: // Use of unassigned local variable 'handler'. SessionEndingEventHandler handler = (sender, e) => { isShuttingDown = true; SystemEvents.SessionEnding -= handler; }; while this does…
Raheel Khan
  • 14,205
  • 13
  • 80
  • 168
6
votes
2 answers

C# Error : Use of unassigned local variable

The error is caused in the for loop : for (i = 0; i < hand.Length; i++) { Console.WriteLine(hand[i]); } I am trying to store the values to be able to display them at a later time. The writeline is there to help me make sure the code actually…
ardox
  • 83
  • 1
  • 5
5
votes
4 answers

Use of unassigned local variable. But always falls into assignment

having this code, I don't understand why if assigning a variable in a finally block doesn't understand it will ALWAYS be assigned. I think I missing a valid option where currency won't be assigned. If you know, will be great to understand why. much…
Bart Calixto
  • 19,210
  • 11
  • 78
  • 114
4
votes
1 answer

Jupyter Notebook, NameError: is not defined, %%time prevents assignment

I came across a very strange bug running a Jupyter Notebook (IPython: 7.4.0) where a variable was not assigned as normally. It took me quite bit of time to figure out the cause, searching in vain all over, variable scope, type conversion and…
Claude COULOMBE
  • 3,434
  • 2
  • 36
  • 39
4
votes
5 answers

ERROR: use of unassigned local variable (for string array)

I am reading connection strings from my App.config file and for that i have following code. try { string[] dbnames; int counter = 0; foreach (ConnectionStringSettings connSettings in ConfigurationManager.ConnectionStrings) { …
Assad Nazar
  • 1,420
  • 5
  • 20
  • 40
4
votes
2 answers

Fortran unassigned array

I just begin learning Fortran, and I come across this issue. Consider the following simple code. PROGRAM random INTEGER, DIMENSION(12):: array PRINT *, array END PROGRAM random The array is not assigned value, but can be printed, and it seems to…
Lelouch
  • 2,111
  • 2
  • 23
  • 33
3
votes
4 answers

How to implement operator=() for a class that has a reference member variable?

I want to have an object that contains a reference, and put that object into a vector... Must I use smart pointers instead of a member references in any object I want to push into a vector? This was what I wanted to do: #include #include…
Philluminati
  • 2,649
  • 2
  • 25
  • 32
3
votes
4 answers

use of unassigned local variable `total`

I want to have a sum of all intervals , but I write this code I have an error stating: use of unassigned local variable total ? enter TimeSpan total; foreach (var grp in query) { TimeSpan interval = TimeSpan.FromMinutes(grp.Minuut); TimeSpan…
Nick_BE
  • 127
  • 2
  • 8
3
votes
3 answers

Jquery assignment fails when inside a for loop

I have a jquery which works correctly when I do this: var slide = []; slide[1] = { hide: function() { $("#slide-1").hide(); }, show: function() { $("#slide-1").show(2000); } …
BenG
  • 1,756
  • 15
  • 17
3
votes
2 answers

memory for unassigned variables in C#

//Consider this declaration string name; Here string variable name is an unassigned variable,does this declaration reserve any memory for name if it does not initialised?
Shamseer K
  • 4,964
  • 2
  • 25
  • 43
1
2 3 4 5 6 7