请考虑以下代码:
public class A
{
}
public class B : A
{
}
public class C : B
{
}
class D
{
public static bool IsDescendantOf(this System.Type thisType, System.Type thatType)
{
/// ???
}
void Main()
{
A cValue = new C();
C.GetType().IsDescendantOf(cValue.GetType());
}
}
Run Code Online (Sandbox Code Playgroud)
实施IsDescendantOf的最佳方法是什么?
您如何看待在给定字节序列开始的System.Stream中找到位置的最佳方法是什么(第一次出现):
public static long FindPosition(Stream stream, byte[] byteSequence)
{
long position = -1;
/// ???
return position;
}
Run Code Online (Sandbox Code Playgroud)
PS最简单但最快速的解决方案是优先考虑的.:)
假设我想定义一个使用Path.GetTempFileName()方法创建临时文件的TempFileStream类.当不再需要TempFileStream的对象时,必须删除临时文件,例如关闭或处置:
class TempFileStream: FileStream
{
string m_TempFileName = Path.GetTempFileName();
public TempFileStream(FileMode fileMode): base(m_TempFileName,fileMode) {}
/// ...
public ovverride Dispose(bool disposing)
{
/// ???
}
}
Run Code Online (Sandbox Code Playgroud)
我该如何简单安全地实现这一目标?
c# ×3
stream ×2
.net ×1
algorithm ×1
bytearray ×1
dispose ×1
filestream ×1
find ×1
reflection ×1
system.type ×1
type-systems ×1