Tag: unassigned variable

在finally块上使用未分配的局部变量

i在这个例子中什么时候可以取消分配? int i; try { i = 2; } catch { i = 3; } finally { string a = i.ToString(); }

使用未分配的局部变量 – if语句

我正在执行以下代码块,并且编译器抱怨未分配的局部变量,并且可以使用一些帮助来识别出什么。 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 1))) strwho = “”; } else if (strType == “07”) { if (rsData[“Text”] != DBNull.Value) strmetades = rsData[“Text”].ToString(); if ((strmetades.Length 1))) strmetades = “”; } 它抱怨所有’if(strType ==“01”)’行,我不确定是什么。 我曾想过为此使用开关,但似乎也遇到了同样的问题。 有任何想法吗?

使用未分配的局部变量。 但总是落入任务

有这个代码,我不明白为什么如果在finally块中分配变量不理解它将始终被分配。 我想我错过了一个无法分配货币的有效选项。 如果你知道,理解为什么会很棒。 非常感谢! 谢谢! CurrencyVO currency; try { if (idConnection.HasValue && idConnection != 0) { currencyConnection = client.GetConnection(idConnection.Value); model.Connection = currencyConnection; } else { int providerUserKey = (int)Models.UserModel.GetUser().ProviderUserKey; currencyConnection = client.GetConnection(providerUserKey); } currency = model.Currencies.SingleOrDefault(c => c.IdCountry == currencyConnection.idcountry) ?? new CurrencyVO(); } catch { currency = new CurrencyVO(); } finally { model.PublishedContainer.Currency = […]

坚持function和布尔

我有一个名为firstRun()函数,在其中我有两个已定义的filesDeleted和dirsDeleted 。 同样在函数里面我有if (filesDeleted == true && dirsDeleted == true) { 当我尝试调试应用程序时,我得到错误 – Use of unassigned local variable ‘filesDeleted’和Use of unassigned local variable ‘dirsDeleted’尝试了很多不同的解决方案,根本不起作用。 这是代码: private void firstRun(bool forceDelete) { string Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), “myLauncher”); string[] Files = Directory.GetFiles(Path); string[] Dirs = Directory.GetDirectories(Path); bool filesDeleted; bool dirsDeleted; if (forceDelete == true) { if (Directory.Exists(Path)) { […]

使用未分配的变量?

在声明paymentstatus是否为null或“if”语句中是否有值时,我得到了未分配变量“ps”的错误使用。 我在想我已经宣布了ps,但显然我做错了。 为什么编译器抱怨这个? 这是上下文中的错误: public IList DailyBestsellersReport() { OrderStatus os; PaymentStatus? ps; ShippingStatus ss; int billingCountryId = 0; int recordsToReturn = 999; int orderBy = 1; int groupBy = 1; int? paymentStatusId = null; if (ps.HasValue) paymentStatusId = (int)ps.Value; // Specifies the time range for sold products/day var range = new { startTimeUtc = DateTime.Today.AddDays(-1), […]

使用未分配的局部变量’multidimension’

我从下面的代码中使用未分配的局部变量’multidimension’得到错误。 我试图将文本文件中返回的数据放在一个多维数组中,方法是将它们拆分并将每一行放入数组中 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; while ((ReadFromReadLine = sr.ReadLine()) != […]

未分配的非可变变量(C#)的值

只是好奇。 如果你走的话: string myString; 它的值为null。 但是如果你去: int myInt; C#中此变量的值是多少? 谢谢 大卫

c#切换问题

我是编程新手并遇到以下代码问题: 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: […]

“使用未分配的局部变量”是什么意思?

我一直收到annualRate,monthlyCharge和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.ReadLine(); Console.Write(“Enter Last Name: “); […]