0

I have define collection of enumerable like this

IEnumerable<TaggedEdge<int, float>> enumerable;

if (tryFunc(World.sortedList_3.IndexOfValue(vector2), ref enumerable) && World.gclass19_0.bool_1)
{
}

And here I am getting error for

Use of unassigned local variable 'enumerable'. Error code : CS0165

So here how can I solve this one ? Please help.

Nisarg Shah
  • 14,151
  • 6
  • 34
  • 55
Hardik Dhankecha
  • 148
  • 1
  • 11
  • 3
    Possible duplicate of [What does "Use of unassigned local variable" mean?](https://stackoverflow.com/questions/5710485/what-does-use-of-unassigned-local-variable-mean) – Nisarg Shah Sep 06 '18 at 06:04
  • Also see: https://stackoverflow.com/questions/256073/c-sharp-error-use-of-unassigned-local-variable – Nisarg Shah Sep 06 '18 at 06:04
  • And https://stackoverflow.com/questions/9233000/why-compile-error-use-of-unassigned-local-variable – Nisarg Shah Sep 06 '18 at 06:04
  • You probably need an out parameter instead of a ref parameter – vc 74 Sep 06 '18 at 06:06
  • ... or assign `null` to it. – Michał Turczyn Sep 06 '18 at 06:08
  • Yes I know that if I assign an local variable and don't use it then it will give me that error but here I have assign two data types so here how to pass null value to enumerable. So my question is exactly for that purpose that how to mention two values for int and float to enumerable. – Hardik Dhankecha Sep 06 '18 at 06:12
  • @hardikdhankecha It's not a warning that you're not using a variable, it's an error that you are using a variable which value may not have been set yet. – vc 74 Sep 06 '18 at 06:19

1 Answers1

2

One is to initialize a new enumrable:

// IEnumerable is now assigned
    IEnumerable<TaggedEdge<int, float>> enumerable = new IEnumerable<TaggedEdge<int, float>>();

    if (tryFunc(World.sortedList_3.IndexOfValue(vector2), ref enumerable) && World.gclass19_0.bool_1)
    {
    }

Or use out:

IEnumerable<TaggedEdge<int, float>> enumerable;

if (tryFunc(World.sortedList_3.IndexOfValue(vector2), out enumerable) && World.gclass19_0.bool_1)
{
}

out means:

means the parameter will be initialized in the method before it returns

ref means:

the parameted will be initialzed outside of the method.

Barr J
  • 10,636
  • 1
  • 28
  • 46