草庐IT

an-interview-question-that-prints

全部标签

c# - 如何在 C# 中使用 Console.Log、Print_R()、Debug.Trace?

PHP有一个名为print_r()和var_dump()的函数,可以显示项目的所有内容。这使得弄清楚事物是什么变得非常容易。在C#中有类似的东西吗?我知道C#中有一个Console.WriteLine("Hello");,但这在MVC中有效吗?我可以在运行应用程序时像flash那样在调试控制台中执行某种类型的debug.trace()吗? 最佳答案 System.Diagnostics.Debug.WriteLine("blah");为了显示对象中的所有变量,您必须覆盖其ToString()方法或编写一个方法来返回您需要的所有对象信

c# - 简易喷油器 : Factory classes that need to create classes with dependencies

我有一个工厂类,它创建了几个不同类型的类。工厂在容器中注册。鉴于它们也具有依赖性,在工厂内部创建类的推荐方法是什么。我显然想避免对容器的依赖,但如果我新建这些类,那么它们将不会使用容器。例如publicclassMyFactory{publicIMyWorkerCreateInstance(WorkerTypeworkerType){if(workerType==WorkerType.A)returnnewWorkerA(dependency1,dependency2);returnnewWorkerB(dependency1);}}所以问题是我从哪里获得这些依赖项。一种选择是使它们成

c# - Visual Studio 2017 : "Object reference not set to an instance of an object" while loading the project

我在VS解决方案中有一个项目可以在VS2015中正确加载,但它似乎在VS2017(RC2)中已损坏。在解决方案资源管理器中,它显示其“加载失败”,当我尝试重新加载它时,我收到一个错误弹出窗口,消息为“对象引用未设置为对象的实例”。我认为这可能是因为VS2017以某种方式更改了.csproj文件以满足他们的需要,但是在将它与VS2015解决方案中的版本进行比较后我发现它们并没有什么不同。有人遇到过这样的事情吗?以及如何修复它?谢谢。 最佳答案 对于VisualStudio2017的我来说,这些建议都没有奏效。有效的方法是关闭所有Vis

c# - 为什么这个程序会出错? `Object synchronization method was called from an unsynchronized block of code`

这段代码有什么问题?我收到“从未同步的代码块调用对象同步方法”。我在谷歌上发现了一个结果,说我可能在锁定之前释放了一个互斥体,但根据我的输出,情况并非如此。这是互斥锁代码,中间没有其他代码。-edit-对不起大家,贴错了。我的输出1W1W2W代码usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Threading;namespacesqliteTest{classProgram{staticvolatileMutexmut1=newMutex();staticvolatileMutexmut

c# - "Compile with/main to specify the type that contains the entry point."

根据下面的代码,我收到以下消息。我相当确定我得到它的“原因”,我只是不知道如何重新排列代码以移动/删除/替换导致错误的语句之一。“使用/main编译以指定包含入口点的类型。”"staticvoidMain(string[]args)"下有一堆代码,我从http://support.microsoft.com/kb/816112为了从自动递增中获取ID,所以当其余代码填充Access数据库时,我可以让它自动递增。任何帮助表示赞赏。也欢迎使用更简单的代码获得结果的建议!namespaceWindowsFormsApplication1{publicpartialclassForm1:For

c# - 尝试读取 xml 文件时的 ASP.Net, "An operation was attempted on a nonexistent network connection"

stringurl="http://www.example.com/feed.xml";varsettings=newXmlReaderSettings();settings.IgnoreComments=true;settings.IgnoreProcessingInstructions=true;settings.IgnoreWhitespace=true;settings.XmlResolver=null;settings.DtdProcessing=DtdProcessing.Parse;settings.CheckCharacters=false;varrequest=(Ht

c# - 内存溢出 : Having an increasing number of Microsoft. CSharp.RuntimeBinder.Semantics

我们目前正在我们的应用程序中寻找一些内存泄漏,当执行一些操作(在我们的应用程序中加载和关闭一个项目)时,我们知道内存总是增加一点点。我们已经找到了很多,但现在,增加最多的10个类是(根据我们的工具ANTSMemoryProfiler8.2):Microsoft.CSharp.RuntimeBinder.Semantics.SYMTBL+KeyMicrosoft.CSharp.RuntimeBinder.Semantics.LocalVariableSymbolMicrosoft.CSharp.RuntimeBinder.Semantics.CONSTVALMicrosoft.CShar

c# - 犀牛模拟 : How to stub a generic method to catch an anonymous type?

我们需要stub一个通用方法,该方法将使用匿名类型作为类型参数来调用。考虑:interfaceIProgressReporter{TReport(TprogressUpdater);}//Unittestarrange:FuncreturnArg=(x=>x);//wewishtoreturntheargument_reporter.Stub(x=>x.Report(null).IgnoreArguments().Do(returnArg);如果在被测方法中对.Report()的实际调用是使用对象作为类型参数完成的,那么这将起作用,但实际上,调用该方法时使用的T是匿名类型。此类型在被测

c# - 错误 : ExecuteReader requires an open and available Connection. 连接的当前状态为打开

我有下面带有DataHelperClass的mvc4网站来执行查询。我的问题有时是,网站以异常为标题。我使用block来处理SqlCommand和SqlDataAdapter但没有成功。请帮助我,对不起我的英语。try{if(_conn.State==ConnectionState.Closed)_conn.Open();using(SqlCommandsqlCommand=newSqlCommand(query,_conn)){sqlCommand.CommandType=CommandType.StoredProcedure;if(parameters!=null)sqlComma

c# - LINQ 到 XML : applying an XPath

有人能告诉我为什么这个程序不枚举任何项目吗?它与RDFnamespace有关吗?usingSystem;usingSystem.Xml.Linq;usingSystem.Xml.XPath;classProgram{staticvoidMain(string[]args){vardoc=XDocument.Load("http://seattle.craigslist.org/sof/index.rss");foreach(varitemindoc.XPathSelectElements("//item")){Console.WriteLine(item.Element("link")