C#如何引用静态类? [英] C# How do I reference static classes?
本文介绍了C#如何引用静态类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以简要解释我如何在静态类中创建静态变量
在我的代码中,我可以创建文档和元素varaibales,
那么如何从我创建的静态类创建变量?
Could someone please explain briefly how I create a static variable in a static class
In my code below I can create the Document and Element varaibales fine,
So how do I create a varaible from a static class that I have created?
public static class Settings
{
public static FileInfo Database;
public static XmlDocument Document;
private static XmlElement Element;
}
public static class FileInfo
{
public static string Location;
public static DateTime Date;
}
原因只是为了进一步了解静态过程。
感谢您的回答。
The reason is simply to understand the static process further.
Thanks for your answers.
推荐答案
您无法创建静态类的实例。它是静态的全部原因是因为你不需要这样做,因为所有属性和方法都是静态的。
我怀疑你想让FileInfo变为非-static(及其属性)。
问候,
伊恩。
PS我想补充一点,System.IO命名空间有一个名为FileInfo的类,您可能需要考虑使用它。 http://msdn.microsoft.com/en-GB/library/system.io。 fileinfo.aspx [ ^ ]
You can''t create an instance of a static class. The whole reason it is static is because you don''t need to do so, since all properties and methods are static.
I suspect you want to make FileInfo non-static (and its properties as well).
Regards,
Ian.
P.S. I would add that the System.IO namespace has a class called FileInfo, which you might want to consider using instead. http://msdn.microsoft.com/en-GB/library/system.io.fileinfo.aspx[^]
静态(C#参考) [ ^ ]
这篇关于C#如何引用静态类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文