小编Mik*_*man的帖子

如果已存在具有文件夹名称的文件,如何创建空文件夹?

我确信有一些简单的东西,我在这里忽略,但我从来没有遇到过这个问题,我不能找到问题的原因.

这是我硬盘上根目录的一个例子:

C:\Folder-1          ( this is a folder )
C:\Folder-2          ( this is a folder )
C:\somename          ( this is a file with no extension )
c:\somename.txt      ( this is a file with an extension )
Run Code Online (Sandbox Code Playgroud)

我想用来创建一个新文件夹的代码是这个方法:

static void Main( string[] args )
{
    try
    {
        // try to create a folder in a directory 
        // where a file with the same name exsists
        createDirectory( "c:\somename" );
    }
    catch
    {
       // this catches an exception "Cannot create directory, because it …
Run Code Online (Sandbox Code Playgroud)

c# directory io file path

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

如何在C#中的多个类实例之间共享一个值?

我正在编写一个类库,用于我们公司的一些工程软件.该库用于定义结构钢形状的属性.在我的每个类对象中,我需要转到指定的文件夹并查找一些xml数据.

我怎样才能创建一个公共变量,我可以在库类之外设置并在实例之间共享如下所示:(如果可以使用以下代码)

    class Program
{
    static void Main(string[] args)
    {
        string someCommonVarialble = @"c:\some\path\where\the\xmlData\are\stored";

        // create some steel shapes
        SteelBeamShape myBeam1 = new SteelBeamShape("W6x9");
        SteelBeamShape myBeam2 = new SteelBeamShape("W10x22");
        SteelPipeShape myPipe1 = new SteelPipeShape("10odx.375wall");
        SteelPipeShape myPipe2 = new SteelPipeShape("24odx.750wall");

        // do some work with objects here
    }
}

public class SteelBeamShape
{
    // constructor
    public SteelBeamShape(string SteelBeamNominalValue)
    {
        // look up some properties base on nominal value in XML tables
        this.xmlDataPath = someCommonVariable;

        // do stuff .... 
    }
}

public …
Run Code Online (Sandbox Code Playgroud)

c# variables class object

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

标签 统计

c# ×2

class ×1

directory ×1

file ×1

io ×1

object ×1

path ×1

variables ×1