gpt4 book ai didi

c# - 当我创建一个新类的实例时,我该如何做到这一点,它必须获得一个参数?

转载 作者:太空宇宙 更新时间:2023-11-03 17:54:23 24 4
gpt4 key购买 nike

关闭。这个问题需要更多 focused .它目前不接受答案。












想改进这个问题?更新问题,使其仅关注一个问题 editing this post .

7年前关闭。




Improve this question




例如:

class WebCrawler
{
List<string> currentCrawlingSite;
List<string> sitesToCrawl;
RetrieveWebContent retwebcontent;

public WebCrawler()
{
}
}

当我制作 WebCrawler = new WebCrawler(parameter here) ...

最佳答案

向您的类添加另一个构造函数;

public WebCrawler(parameter here)
{
}

之后,您需要 删除 无参数的一个构造函数,因此人们可以在不提供任何参数的情况下创建您的类的实例。

您可以创建它的实例
WebCrawler w = new WebCrawler(parameter here);
您可以从 Instance Constructors 阅读更多信息

这是 DEMO .

关于c# - 当我创建一个新类的实例时,我该如何做到这一点,它必须获得一个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15543742/

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