English 中文(简体)
C#中几个来源档案的类型
原标题:Typedef in C# across several source files
  • 时间:2010-05-06 15:35:19
  •  标签:
  • c#

我写了一张包裹,希望用一种等效法来界定在大量来源档案中应当有效的某些类型。 这些“类型”仅与[u]int16/32/64_t不同,但有助于区分功能参数。

可以使用<代码>使用MyId=System。 Int32;,但这需要在每一档案中重新公布,直至我看到......。 是否有更好的办法?

最佳回答

一种替代做法是使用一种具有含蓄地转换为基本类型的内容。

public struct MyHandle
{
    private int _handle;

    internal MyHandle(int handle)
    {
        _handle = handle;
    }

    public static implicit operator int(MyHandle handle)
    {
        return handle._handle;
    }
}

你的内部法典仍然可以通过默示转换将其用作基本类型(在此情况下),但你将它作为强类暴露于使用者。 你们的使用者也可以看到暗中的价值,尽管这种价值对他们来说是毫无意义的。 他们可以直接 cast你。 手提型,因为建筑商是内部的,你没有为另一方向提供转换操作员。

问题回答

自2006年以来 我假定你想要区分合法使用“IDnt32”和你的习俗,是你们需要用人工指你们希望使用的一切东西。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签