摘要
typeof(ISomeInterface).BaseType是null; typeof(object).BaseType也是null根据定义.从而:
typeof(object).BaseType==typeof(ISomeInterface).BaseType -> true
Run Code Online (Sandbox Code Playgroud)
它(语义上)可能意味着System.Object一个接口,不是吗?在c#中,所有类都继承自System.Object,但接口不继承.接口实际上是契约,而不是任何类的基类型,并且只能从其他接口派生.
所以我想知道是否typeof(object).BaseType应该与接口相同?
说明
我认为这是基本的数学逻辑.I处理null为0和typeof(object)为1,使得找到的基类型某种类型的就像找到许多的因素.
在这种假设下,null可以是任何类型的推导,例如0任意数量的倍数.并且typeof(object)将是任何类的基本类型,就像1是任何数字的因素,甚至本身.实际归国null的typeof(object).BaseType,但是,打破了这一假设.这似乎说这0是一个因素,1但不是任何其他数字的因素.
此外,如果我们使用一种方法来SomeType递归地找到基类型,我们不能总是说它SomeType不是一个类,因为它BaseType是null,typeof(object).BaseType也是null.
如果这似乎是矛盾的
typeof(object).BaseType==typeof(object) -> true
Run Code Online (Sandbox Code Playgroud)
提出它的基本类型本身,但实际上并不是实体和合同之间的区别?
更新:
我最初说过:
它可能意味着
System.Object一个接口,不是吗?
我想说的是它似乎很困惑.这是我表达不好的描述的错,并且很抱歉导致答案集中在那上面.
我有这个:
string strings = "a b c d d e";
Run Code Online (Sandbox Code Playgroud)
我需要类似的东西string.Contains(),但我不仅需要知道字符串是否存在(如果在字母上方),而且还需要知道它是否仅存在一个单一时间.
我怎样才能做到这一点?
我确信这已被问了一百万次,但是当我搜索所有的例子都不太合适时,所以我想我还是应该问它.
我有两个数组,每个数组总共包含6个项目.例如:
string[] Colors=
new string[] { "red", "orange", "yellow", "green", "blue", "purple" };
string[] Foods=
new string[] { "fruit", "grain", "dairy", "meat", "sweet", "vegetable" };
Run Code Online (Sandbox Code Playgroud)
在这两个阵列之间,有36种可能的组合(例如"红色水果","红色颗粒").
现在我需要进一步将这些组合成六组唯一值.
例如:
meal[0]=
new Pair[] {
new Pair { One="red", Two="fruit" },
new Pair { One="orange", Two="grain" },
new Pair { One="yellow", Two="dairy" },
new Pair { One="green", Two="meat" },
new Pair { One="blue", Two="sweet" },
new Pair { One="purple", Two="vegetable" }
};
Run Code Online (Sandbox Code Playgroud)
在哪里吃饭
Pair[][] meal;
Run Code Online (Sandbox Code Playgroud)
在我的"餐"列表中不能重复任何元素.因此,只有一个"红色"项目和一个"肉"项目等.
我可以根据前两个数组轻松创建对,但我在如何最好地将它们组合成唯一组合方面做了一个空白.
编写此方法的最具可读性(和惯用语)是什么?
private bool BytesAreValid(byte[] bytes) {
var t = (bytes[0] | bytes[1] | bytes[2]);
return t != 0;
}
Run Code Online (Sandbox Code Playgroud)
我需要一个函数来测试一个不是以它开头的文件的前三个字节00 00 00.
没有做太多的字节操作.上面的代码对我来说似乎不正确,因为t推断了类型Int32.
我正在尝试将这两个列表组合在一起:
var quartEst = Quarterly_estimates
.OrderByDescending (q => q.Yyyy)
.ThenByDescending (q => q.Quarter)
.Where (q =>
q.Ticker.Equals("IBM")
&&
q.Eps != null
)
.Select (q => new {
ticker = q.Ticker,
Quarter = q.Quarter,
Year = q.Yyyy,
Eps = q.Eps})
.AsEnumerable()
.Where (q => Convert.ToInt32(string.Format("{0}{1}", q.Year, q.Quarter)) > Convert.ToInt32(finInfo) );
var quartAct = Quarterlies
.OrderByDescending (q => q.Yyyy)
.ThenByDescending (q => q.Quarter)
.Where (q =>
q.Ticker.Equals("IBM")
&&
Convert.ToInt16(q.Yyyy) >= DateTime.Now.Year - 3
)
.Select (q => new {
Tick = q.Ticker, …Run Code Online (Sandbox Code Playgroud) 说我有以下代码:
// a class like this
class FirstObject {
public Object OneProperty {
get;
set;
}
// (other properties)
public Object OneMethod() {
// logic
}
}
// and another class with properties and methods names
// which are similar or exact the same if needed
class SecondObject {
public Object OneProperty {
get;
set;
}
// (other properties)
public Object OneMethod(String canHaveParameters) {
// logic
}
}
// the consuming code would be something like this
public static …Run Code Online (Sandbox Code Playgroud) 我想知道为什么这个有效?
例如,我有一些看起来像这样的执行器类:
public class Executor
{
public void Execute(Action action)
{
action();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我有一些需要被执行的类看起来像:
public class NeedToBeExecuted
{
public void Invoke()
{
Executor executor = new Executor();
executor.Execute(DoSomething);
}
private void DoSomething()
{
// do stuff private
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么这是工作我将私有方法传递给其他类?
这不是封装问题吗?
我们假设我使用此站点上的算法使用公钥 - 私钥加密和解密数据:
CodeProject上C#.NET中的公钥RSA加密
现在,让我们说有人使用我的公钥使用另一种算法加密他的数据并将其发送给我.使用不同的算法(如网站上的算法),我能够使用我的私钥解密信息吗?或者这是不可能的,因为算法不同?
我的观点是,假设使用的密钥是正确的,如果使用不同的加密算法,最终结果是否总是相同的?
是否有一些标准的方法来加密信息,使其可以在不同的机器上解密,也许是不同的编程语言?
像两个重叠的线段一样,我们可以找到无限的交点.列举所有这些点可能没有意义,我们可能只想表明这个集合是无限的.
浮点数已定义NegativeInfinity和PositiveInfinity.表示计数或序数的数字似乎不一定使用浮点数,但是,整数没有定义为表示无穷大的东西.
所以我试着实现无限的可枚举.但我突然对"可枚举"一词感到困惑.
有没有更好的方法来解决这个问题?并且无数可枚举仍然可以枚举?
码
public partial class Infinity: IEnumerable<object> {
IEnumerator<object> IEnumerable<object>.GetEnumerator() {
for(; ; )
yield return Infinity.Enumerable;
}
public IEnumerator GetEnumerator() {
for(; ; )
yield return Infinity.Enumerable;
}
public Infinity LongCount(
Func<object, bool> predicate=default(Func<object, bool>)) {
return Infinity.Enumerable;
}
public Infinity Count(
Func<object, bool> predicate=default(Func<object, bool>)) {
return Infinity.Enumerable;
}
public static readonly Infinity Enumerable=new Infinity();
}
Run Code Online (Sandbox Code Playgroud)编辑:
谢谢回答.我不混淆IEnumerable和IEnumerator.GetEnumerator …
我在互联网上阅读了2 - 3个二进制索引树(AKA Fenwick树)的教程,但我不明白它实际上做了什么以及背后的想法是什么BIT.我读的教程是
请帮我让我明白BIT.
c# ×9
algorithm ×2
reflection ×2
types ×2
.net ×1
byte ×1
bytearray ×1
combinations ×1
cryptography ×1
encryption ×1
ienumerable ×1
lambda ×1
linq ×1
matrix ×1
oop ×1
permutation ×1
pki ×1
runtime ×1
semantics ×1
string ×1
terminology ×1
tree ×1
union ×1