6 Unassigned Error String
Contents |
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 error use of unassigned local variable c# developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question use of unassigned local variable in c# string array x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join use of unassigned local variable c# int array them; it only takes a minute: Sign up ERROR: use of unassigned local variable (for string array) up vote 4 down vote favorite 1 I am reading connection strings from my App.config file and for that i have following code.
Use Of Unassigned Local Variable C# String
try { string[] dbnames; int counter = 0; foreach (ConnectionStringSettings connSettings in ConfigurationManager.ConnectionStrings) { dbnames[counter] = connSettings.Name; counter++; } return dbnames; } catch { throw; } this code giving me error use of unassigned local variable for dbnames. i will have multiple connection strings in my App.config. They can be none,1,2 and so on. Depending on the needs. so i cant statically assign the dbname size. Because there can be a scenario if they exceed the value of assigned use of unassigned local variable int array size. eg. if i assign it a size of 5, and what if i get 6th connection string. and if i have 1, then remaining 4 will be a memory wastage. If i am wrong then let me know. Thanks. c# .net arrays c#-4.0 unassigned-variable share|improve this question edited Jan 27 '11 at 10:53 Cody Gray 145k23276368 asked Jan 27 '11 at 10:43 booota 66841226 3 Fix it with: string[] dbnames = null; Run the code, then understand why it does not work. –leppie Jan 27 '11 at 10:48 1 @leppie: Clever, i've +1'd. Also, one could say: uninitialized variable has no initializer. \o/ –Romain Jan 27 '11 at 10:49 yeah right, i tried null and it was then jumping to the exception 'catch' section –booota Jan 27 '11 at 10:51 Good, first step is understanding the root problem. Now follow the answers below to solved the rest of the problem :) –leppie Jan 27 '11 at 10:53 If I have 3 connection strings in my appSettings tag, how can i determine which one is the default (obviously when i will select one to be taken as default)? –booota Jan 28 '11 at 7:07 add a comment| 4 Answers 4 active oldest votes up vote 8 down vote accepted Use this while initializing the array. string[] dbnames = new string[ConfigurationManager.ConnectionStrings.Count]; OR use List
Studio Languages , .NET Framework > Visual C# Question 0 Sign in to vote as per the followng use of unassigned local variable c# byte code including the comment line in the offending line. Thank you.
Use Of Unassigned Variable C#
public partial class Form1 : Form { List> AlarmLogLists = new List
>(); private void button1_Click(object sender, EventArgs e)
C# Use Of Unassigned Local Variable List
{ for (int i = 1; i < logLines.Length; i++) { List> AlarmLogLists = new List
>(); private void button1_Click(object sender, EventArgs e) { for (int i = 1; i < logLines.Length; i++) https://social.msdn.microsoft.com/Forums/vstudio/en-US/08e2e42d-e790-4fc3-8353-2cd180e62dcd/how-do-i-solve-use-of-unassigned-local-variable-error?forum=csharpgeneral { List
Smartphones More Software Memory Power Supplies Peripherals Displays Automotive PSUs Android Your question Get the answer Tom's Hardware>Forum>Windows XP>Printer Problems with upgrade> Printer Problems with http://www.tomshardware.com/forum/119572-45-printer-problems-upgrade upgrade Tags: Printers Hewlett Packard Microsoft Windows XP Last response: July 8, 2004 10:48 PM in Windows XP Share sharon July 7, 2004 10:41:09 PM Archived from groups: microsoft.public.windowsxp.print_fax (More info?) I just upgraded to XP home from 98 Upgraded driver Have HP officejet T65 printer after all installations Error appears -6 unassigned error string???? Help I have no printer. Thanks More about use of : printer problems upgrade Anonymous a b α HP July 8, 2004 2:19:56 AM Archived from groups: microsoft.public.windowsxp.print_fax (More info?) You must uninstall and reinstall: http://www.coribright.com/Windows/Article%20One.htm -- Cari (MS-MVP Windows Client - Printing, Imaging & Hardware) www.coribright.com "Sharon"