-1
A
回答
1
这是一个不安全的指针。 Unsafe Code Tutorial
下面是使用它的一个例子:How to pull out alpha and count digits using regex?
private static unsafe List<long> ParseNumbers(char[] input)
{
var r = new List<long>();
fixed (char* begin = input)
{
char* it = begin, end = begin + input.Length;
while (true)
{
while (it != end && (*it < '0' || *it > '9'))
++it;
if (it == end) break;
long accum = 0;
while (it != end && *it >= '0' && *it <= '9')
accum = accum * 10 + (*(it++) - '0');
r.Add(accum);
}
}
return r;
}
0
那些是Pointer types。
在不安全的上下文中,类型可能是指针类型以及值类型或引用类型。指针类型声明采用以下形式之一:
type* identifier;
void* identifier; //allowed but not recommended
1
看一看Pointer types (C# Programming Guide)
在不安全上下文中,一个类型可以是指针类型,值类型,或 参考类型。指针类型声明采用以下格式之一:
type * identifier;
void * identifier; //允许但不建议
0
它们被称为Pointer types
在不安全上下文中,一个类型可以是指针型以及一个 值类型或引用类型。但是,指针类型也可能是 ,用于不安全上下文之外的typeof表达式中,因为此类用法并非不安全。
指针型被写入作为非托管型或关键字void, 后跟一个*标记:
在指针类型的*之前指定的类型被称为指针的 所指类型类型。它表示指针类型的值所指向的 变量的类型。
与引用(引用类型的值)不同,指针不是由垃圾收集器跟踪的 - 垃圾收集器没有指针和指向的数据的 知识。对于这个 原因,指针不允许指向包含引用的引用或 结构,并且指针 的引用类型必须是非托管类型。
0
这是指针在C#
请花时间阅读本Unsafe Code Tutorial
using System;
class Test
{
// The unsafe keyword allows pointers to be used within
// the following method:
static unsafe void Copy(byte[] src, int srcIndex,
byte[] dst, int dstIndex, int count)
{
if (src == null || srcIndex < 0 ||
dst == null || dstIndex < 0 || count < 0)
{
throw new ArgumentException();
}
int srcLen = src.Length;
int dstLen = dst.Length;
if (srcLen - srcIndex < count ||
dstLen - dstIndex < count)
{
throw new ArgumentException();
}
// The following fixed statement pins the location of
// the src and dst objects in memory so that they will
// not be moved by garbage collection.
fixed (byte* pSrc = src, pDst = dst)
{
byte* ps = pSrc;
byte* pd = pDst;
// Loop over the count in blocks of 4 bytes, copying an
// integer (4 bytes) at a time:
for (int n =0 ; n < count/4 ; n++)
{
*((int*)pd) = *((int*)ps);
pd += 4;
ps += 4;
}
// Complete the copy by moving any bytes that weren't
// moved in blocks of 4:
for (int n =0; n < count%4; n++)
{
*pd = *ps;
pd++;
ps++;
}
}
}
static void Main(string[] args)
{
byte[] a = new byte[100];
byte[] b = new byte[100];
for(int i=0; i<100; ++i)
a[i] = (byte)i;
Copy(a, 0, b, 0, 100);
Console.WriteLine("The first 10 elements are:");
for(int i=0; i<10; ++i)
Console.Write(b[i] + " ");
Console.WriteLine("\n");
}
}
和输出
The first 10 elements are:
0 1 2 3 4 5 6 7 8 9
我的牙齿这会给你一个想法,以低调的指针在C#以及如何使用它
好运
相关问题
- 1. C中的数据类型
- 2. 在C#中的列表中保存不同类型的数据#
- 3. 类型的数据类型来表示一个数
- 4. Haskell的图形数据类型表示
- 5. 数据类型在C#
- 6. C++中等效数据类型的C#
- 7. C++类中的任意数据类型
- 8. 数据表C#中的线性内插 - 确定数据类型
- 9. 如何在C#中表示具有可变数量列的通用数据类型的表格数据?
- 10. 数据类型模型C++
- 11. 在C中比较数据类型#
- 12. 数据类型混合在c中
- 13. 在C++中测试数据类型
- 14. 在C中存储数据类型
- 15. 在C#中查找数据类型#
- 16. 数据类型在java中表示一个十进制数字
- 17. 在C#中的所有数据类型下拉列表
- 18. 理解在Matlab中表示数据类型的字符串
- 19. 类型的数据帧列表在R中显示尾随零
- 20. 在Excel中构建层级类型的数据表示
- 21. 数据类型的OBJ-C
- 22. C#不同数据类型列表
- 23. 将列表数据填充到数据模型类中C#
- 24. 数据辨识类型在C/C++
- 25. 对象在C#表示某些类型
- 26. C中的数据类型的问题
- 27. 由多种其他数据类型之一选择表示的数据类型
- 28. 表变量中的表数据类型
- 29. 将数据表示数据反映到类对象中C#
- 30. 模糊c-表示分类数据
这是C/C++,不C#的。这是一个指针:http://www.cs.cf.ac.uk/Dave/C/node10.html – GrandMasterFlush
下面是在C#中的数据类型:http://msdn.microsoft.com/en-us/library/ms173104 (v = VS.80).ASPX – Max
@GrandMasterFlush眼罩离:) – sehe