gpt4 book ai didi

c# - 如果变量为空,为什么我没有得到空异常?

转载 作者:行者123 更新时间:2023-12-02 14:11:36 25 4
gpt4 key购买 nike

这是代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Text.RegularExpressions;
using System.IO;
using unfreez_wrapper;
using Shell32;


namespace DownloadImages
{
public partial class Form1 : Form
{
string rainMapToRead;
string UrlsPath;
int counter;
UnFreezWrapper uf;
string localFilename;
string stringForSatelliteMapUrls;
string satelliteMapToRead;
List<string> StartTags;
List<string> LastTags;
List<string> Maps;

ExtractImages ei;

public Form1()
{
InitializeComponent();




using (WebClient client = new WebClient())
{
client.DownloadFile("http://www.sat24.com/foreloop.aspx?type=1&continent=europa#",localFilename + "rainMap.html");
client.DownloadFile("http://www.sat24.com/en/eu?ir=true", localFilename + "satelliteMap.html");
}

rainMapToRead = File.ReadAllText(localFilename + "rainMap.html");
satelliteMapToRead = File.ReadAllText(localFilename + "satelliteMap.html");

localFileName 位于目录路径之前。但现在我没有定义它,所以它是空的。但即使它为空,rainMapToRead 也不为空,并且能够找到并读取“rainMap.html”

我的意思是,如果变量 localFilename 为 null,则文件被下载到? C: ?达:?如果它为空,默认位置是什么?

最佳答案

因为这个 (null + "hello")C# 中是完全合法的表达式。

如果你看How to: Concatenate Multiple Strings (C# Programming Guide) ,你可以找到以下语句:

In string concatenation operations, the C# compiler treats a null string the same as an empty string, but it does not convert the value of the original null string.

关于c# - 如果变量为空,为什么我没有得到空异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18872308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com