unassigned-variable

Use of unassigned local variable - if statements

萝らか妹 提交于 2019-12-06 03:59:23
I'm doing the following block of code and the compiler is complaining about unassigned local variables and could use some help identifying what's up. while (rsData.Read()) { if (rsData["TYPE"] != DBNull.Value) strType = rsData["TYPE"].ToString().Trim(); if (strType == "01") { if (rsData["Text"] != DBNull.Value) strwho = rsData["Text"].ToString(); if ((strwho.Length < 10 || (strwho.IndexOf("NULL") > 1))) strwho = ""; } else if (strType == "07") { if (rsData["Text"] != DBNull.Value) strmetades = rsData["Text"].ToString(); if ((strmetades.Length < 10 || (strmetades.IndexOf("NULL") > 1)))

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

孤人 提交于 2019-12-05 12:47:22
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) { 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

Use of unassigned local variable that is assigned

情到浓时终转凉″ 提交于 2019-12-04 05:24:54
问题 The below code runs a 'for' loop to create months 1 through 12 then names each month Jan through Dec according to their number. That pieces compiles fine. At the bottom where I try to write the month name on the screen is where it is failing. It says "use of unassigned local variable 'monthName'; however monthName was just used previously and is declared above. Any help you could provide would be greatly appreciated. for (int month = 1; month <= 12; month++) { string monthName; double

Use of unassigned variable?

时光毁灭记忆、已成空白 提交于 2019-12-02 09:11:22
问题 I'm getting the error use of unassigned variable "ps" when declaring if paymentstatus is null or has value in the "if" statement. I'm thinking that i allready declared ps but obviously im doing something wrong. Why does the compiler complain about this? Here's the error in it's context: public IList<BestsellersReportLine> DailyBestsellersReport() { OrderStatus os; PaymentStatus? ps; ShippingStatus ss; int billingCountryId = 0; int recordsToReturn = 999; int orderBy = 1; int groupBy = 1; int?

use unassigned local variable 'multidimension'

萝らか妹 提交于 2019-11-29 18:14:41
I am getting an error use unassigned local variable 'multidimension' from below code. I am trying to put the data returned back from the text file in a multidimensional array by splitting them and put each row in in the array private void button1_Click_1(object sender, EventArgs e) { string[,] Lines; //string[][] StringArray = null; //to get the browsed file and get sure it is not curropted try { DialogResult result = openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { using (StreamReader sr = new StreamReader(openFileDialog1.FileName)) { string[] data= null; string ReadFromReadLine

Value of unassigned non-nullable variable (C#)

风流意气都作罢 提交于 2019-11-29 06:58:22
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 Firstly, note that this is only applicable for fields, not local variables - those can't be read until they've been assigned, at least within C#. In fact the CLR initializes stack frames to 0 if you have an appropriate flag set - which I believe it is by default. It's rarely observable though - you have to go through some grotty hacks. The default value of int is 0 - and for any type, it's essentially the value represented by a bit pattern full of zeroes

Value of unassigned non-nullable variable (C#)

烈酒焚心 提交于 2019-11-28 00:37:22
问题 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 回答1: Firstly, note that this is only applicable for fields, not local variables - those can't be read until they've been assigned, at least within C#. In fact the CLR initializes stack frames to 0 if you have an appropriate flag set - which I believe it is by default. It's rarely observable though - you have to go through some grotty hacks. The default

c# switch problem

非 Y 不嫁゛ 提交于 2019-11-27 15:11:11
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'; 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(); } The compiler says: Use of unassigned local variable 'alphaChar' But I'm assigning it in my switch block. I'm

c# switch problem

主宰稳场 提交于 2019-11-26 17:04:36
问题 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'; 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(); } The

What does “Use of unassigned local variable” mean?

霸气de小男生 提交于 2019-11-26 00:19:37
问题 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[] 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