相关疑难解决方法(0)

在C#中,我应该使用string.Empty或String.Empty或""来初始化字符串吗?

在C#中,我想用空字符串初始化字符串值.

我该怎么做?什么是正确的方法,为什么?

string willi = string.Empty;
Run Code Online (Sandbox Code Playgroud)

要么

string willi = String.Empty;
Run Code Online (Sandbox Code Playgroud)

要么

string willi = "";
Run Code Online (Sandbox Code Playgroud)

或者是什么?

.net c# string initialization

689
推荐指数
18
解决办法
21万
查看次数

使用SQLDataReader时"无数据存在时读取无效"

这是我的GeneralFunctions:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for GeneralFunctions
/// </summary>
public class GeneralFunctions
{
    public GeneralFunctions ()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static DataTable GetData ( string query )
    {
        SqlDataAdapter dataAdapter;
        DataTable table;

        try
        {
            dataAdapter = new SqlDataAdapter( query, GetConnectionString() );
            table = new DataTable();

            dataAdapter.Fill( table );
            return table;
        }
        catch ( Exception ex )
        {
        } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net

5
推荐指数
1
解决办法
1万
查看次数

内存中的string.Empty和null有什么区别

我了解分配值与不分配值的区别,我想了解的是分配如何在内存中处理。

什么将存储在HEAP和堆栈中?哪一个是最有效的?

例如,使方法签名更有效

private Item GetItem(pageModel page, string clickableText = null);
Run Code Online (Sandbox Code Playgroud)

要么

private Item GetItem(pageModel page, string clickableText = "");
Run Code Online (Sandbox Code Playgroud)

注意:

问题不在于使用哪个。这是关于它们在内存上的差异。提议的方法可能被调用数百次-因此,不同的变量分配可能/会产生影响吗?

c#

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

C# - 使用未分配的局部变量'stringnamehere'

这是我的代码:

        private void startButton_Click(object sender, EventArgs e)
    {
        DriveInfo[] drives = DriveInfo.GetDrives();
        string drivenames;
        for (int i = 0; i < drives.Count(); i++)
        drivenames = drives[i].Name;
        MessageBox.Show(drivenames); // --> For debug purposes only
        strCmdText = "del /f /s " + drivenames + "*.sfk";
        System.Diagnostics.Process.Start("CMD.exe", strCmdText);
    }
Run Code Online (Sandbox Code Playgroud)

我试图将计算机上的驱动器号写入字符串,但是,当我尝试使用该字符串时,它表示使用未分配的局部变量'drivenames'.这有什么问题?

c#

0
推荐指数
2
解决办法
212
查看次数

标签 统计

c# ×4

.net ×1

asp.net ×1

initialization ×1

string ×1