Error 6 Use Of Unassigned Local Variable
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss error 1 use of unassigned local variable the workings and policies of this site About Us Learn more error 2 use of unassigned local variable about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack c# use of unassigned local variable Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping use of unassigned local variable unity each other. Join them; it only takes a minute: Sign up C# error: Use of unassigned local variable up vote 22 down vote favorite 1 I'm not sure why I'm getting this error, but shouldn't this code compile, since I'm already checking to see if queue is getting initialized? public static void Main(String[] args) { Byte maxSize; Queue
Use Of Unassigned Local Variable String
queue; if(args.Length != 0) { if(Byte.TryParse(args[0], out maxSize)) queue = new Queue(){MaxSize = maxSize}; else Environment.Exit(0); } else { Environment.Exit(0); } for(Byte j = 0; j < queue.MaxSize; j++) queue.Insert(j); for(Byte j = 0; j < queue.MaxSize; j++) Console.WriteLine(queue.Remove()); } So if queue is not initialized, then the for loops aren't reachable right? Since the program already terminates with Environment.Exit(0)? Hope ya'll can give me some pointers :) Thanks. c# initialization share|improve this question edited Nov 2 '08 at 0:17 Blair Conrad 98.6k17106100 asked Nov 1 '08 at 20:33 jkidv 1,11131212 6 I can't give you any pointers, but I hope you can get a handle on this one. –wprl Nov 1 '08 at 20:40 add a comment| 5 Answers 5 active oldest votes up vote 65 down vote accepted The compiler doesn't know that the Environment.Exit() is going to terminate the program; it just sees you executing a static method on a class. Just initialize queue to null when you declare it. Queue queue = null; share|improve this
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or
Use Of Unassigned Local Variable Array
posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss use of unassigned local variable struct Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only use of unassigned local variable datetime takes a minute: Sign up Use of unassigned local variable error C# up vote 0 down vote favorite This is with regard to previous question posted a while ago Remove -1 entry from integer array I know there are blazing http://stackoverflow.com/questions/256073/c-sharp-error-use-of-unassigned-local-variable fast solutions , one line answers as posted in answer section to previous posted question , but being a newbie I tried doing by for loops. int[] arr = new int[]{ 1, -1, -1, 1 }; int[] new_arr; int index = 0; for (int i = 0; i < arr.Length; i++) { // Console.WriteLine(arr[i]); if (arr[i] == -1) continue; else new_arr[index++] = arr[i]; } I am getting error Use of unassigned local variable 'new_arr' what am I doing wrong. EDIT int[] http://stackoverflow.com/questions/12833857/use-of-unassigned-local-variable-error-c-sharp arr = new int[]{ 1, -1, -1, 1 }; int[] new_arr = new[arr.Length]; //Error being shown at this line int index = 0; for (int i = 0; i < arr.Length; i++) { if (arr[i] == -1) continue; else new_arr[index++] = arr[i]; } for(int j=0;j
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site http://stackoverflow.com/questions/5710485/what-does-use-of-unassigned-local-variable-mean About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up What does “Use of use of unassigned local variable” mean? up vote 17 down vote favorite 3 I keep getting this error for annualRate, monthlyCharge, and lateFee..And for the death of me I cannot figure out why. Any help would be greatly appriciated! 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; use of unassigned 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: "); balance = Convert.ToDouble(Console.ReadLine()); Console.Write("Is This Account Late?: "); status = Console.ReadLine().Trim().ToLower(); if (creditPlan == "0") { annualRate = 0.35; //35% lateFee = 0.0; monthlyCharge = balance * (annualRate * (1 / 12)); return; } if (creditPlan == "1") { annualRate = 0.30; //30% if (status == "y") { late = true; } else if (status == "n") { late = false; } if (late == true) { lateFee = 25.00; } monthlyCharge = balance * (annualRate * (1 / 12)); return; } if (creditPlan == "2") { annualRate = 0.20; //20% if (status == "y") { late = true; } else if (status == "n") { late = false; } if (late == true) { lateFee = 35.00; } if (balance > 100) { monthlyCharge = balance * (annualRate * (1 / 12)); } else { monthlyCharge = 0; } return; } if