标签: unassigned-variable

使用未分配的布尔值?局部变量

我有这个:

   foreach (Software.dsBDD.list_table21 row in dataTable.Rows)
        {
            PictureBox box;
            MemoryStream stream;
            Panel panel;
            Label label;
            bool? pass;
            if (this.pass.HasValue && this.end)
            {
               pass = this.pass;
            }
            if ((pass.GetValueOrDefault() && pass.HasValue) || row.view_only)
        }
Run Code Online (Sandbox Code Playgroud)

“GetValueOrDefault”附近的变量“pass”用下划线表示为错误:“使用未分配的局部变量 pass”。我不明白为什么这个变量是未分配的,因为在同一行中,“HasValue”附近有“pass”并且它被分配了。我的语法错误在哪里?!

c# variables unassigned-variable

0
推荐指数
1
解决办法
2568
查看次数

使用未分配的局部变量错误

我收到一个错误:

"使用未分配的局部变量'PostData'"

在方法中编译以下语句时.我的意图是获取包含XML SOAP标头的"字符串"值并将其转换为XMLDictionaryWriter对象.请参阅下面的代码:

Stream PostData;
byte[] buffer = Encoding.ASCII.GetBytes(x509.CreateX509SoapEnvelope());
PostData.Write(buffer, 0, buffer.Length); // error here
XmlDictionaryWriter xmlwriter = XmlDictionaryWriter.CreateTextWriter(PostData, Encoding.ASCII);
request.Headers.WriteHeaderContents(0,xmlwriter);
Run Code Online (Sandbox Code Playgroud)

仅供参考,输出x509.CreateX509SoapEnvelope()是一个字符串,我测试了那部分,它的工作原理.我标记了上面的代码,以显示错误发生的位置.需要帮助解决错误以及如何解决它?

c# unassigned-variable

-1
推荐指数
1
解决办法
2064
查看次数

如何在Python中区分未分配的变量和零?

一些外部代码运行我的以下代码的功能:

def __init__(self,weights=None,threshold=None):

    print "weights: ", weights
    print "threshold: ", threshold

    if weights:
        print "weights assigned"
        self.weights = weights
    if threshold:
        print "threshold assigned"
        self.threshold = threshold
Run Code Online (Sandbox Code Playgroud)

这段代码输出:

weights:  [1, 2]
threshold:  0
weights assigned
Run Code Online (Sandbox Code Playgroud)

即打印操作符的行为类似于threshold零,而if操作符的行为类似于未定义的操作符.

什么是正确的解释?怎么了?threshold参数的状态是什么以及如何识别它?

python unassigned-variable python-2.7

-1
推荐指数
1
解决办法
548
查看次数

为什么使用未分配的局部变量.C#.创建一个新节点

我有以下代码的问题.我需要创建一个新的pcba节点,如果它与之前创建的不同.如果该变量没有改变,我需要使用相同的变量.

foreach (XmlNode node in dc.DocumentElement.ChildNodes)
            {
                PCBA pcb = null;

                if (serialPCB != node.Attributes["PCBpos"].Value.ToString())
                    pcb = new PCBA();

                pcb.PCBA_Status = status;
                long number = 0;
                bool validation = false;
                if (node.Attributes != null && node.Attributes["PCBpos"] != null)
                  {
                    validation = long.TryParse(node.Attributes["PCBpos"].Value, out number);
                  }
                 //bool validation = long.TryParse(node.Attributes["PCBpos"].Value, out number);
                if (validation == true)
                {
                    pcb.PCBA_POSITION = node.Attributes["PCBpos"].Value.ToString();
                    serialPCB = node.Attributes["PCBpos"].Value.ToString();

                    if (status != "PASS")
                    {
                        List<Group> groups = new List<Group>();
                        Group group = new Group();

                        group.Group_Name = node.Attributes["COMP_NAME"].Value.ToString(); …
Run Code Online (Sandbox Code Playgroud)

c# unassigned-variable

-2
推荐指数
1
解决办法
124
查看次数

使用未分配的参数'q'

错误使用未分配的参数'q'和'g',请更正我做错的地方.提前致谢.

using System;  
using System.Collections.Generic;
using System.Linq;
using System.Text;  
using System.Threading.Tasks;   

class Program  
{  
    static void Main(string[] args)  
    {  
        int p = 23;  
        int f = 24;  
        Fun(out p, out f);  
        Console.WriteLine("{0} {1}", p, f);  

    }  
    static void Fun(out int q, out int g)  
    {  
        q = q+1;  
        g = g+1;  
    }  
}  
Run Code Online (Sandbox Code Playgroud)

c# unassigned-variable

-3
推荐指数
1
解决办法
1921
查看次数

标签 统计

unassigned-variable ×5

c# ×4

python ×1

python-2.7 ×1

variables ×1