问题描述
Hello Every One,
我的项目中有一个ResultClass。
我正在创建该类的对象
Hello Every One,
I am having One ResultClass in my project.
I am creating the object of that class
<pre lang="c#">ResultClass r=new ResultClass();</pre>
one more thing i am doing is
<pre lang="cs">
//m_ResultList is temp resultclass object
ResultClass m_RecedResult = (ResultContainer)m_ResultList[0];
m_ResultList.RemoveAt(0);</pre>
现在我不理解这两个声明之间的区别。新关键字的区别是什么obj传递的类型。
now i am not understanding the difference between this both statement.what is difference between new keyword and type of obj passing.
推荐答案
public class BaseC<br />
{<br />
public int x;<br />
public void Invoke() { }<br />
}<br />
public class DerivedC : BaseC<br />
{<br />
new public void Invoke() { }<br />
}
new Constraint:用于限制可能用作泛型声明中类型参数的参数的类型。
new Constraint : Used to restrict types that might be used as arguments for a type parameter in a generic declaration.
class ItemFactory<t> where T : new()<br />
{<br />
public T GetNewItem()<br />
{<br />
return new T();<br />
}<br />
}</t>
typeof:
用于获取类型的System.Type对象。 typeof表达式采用以下形式:
System.Type type = typeof(int);
您可以在MSDN上找到更多信息。 :)
-KR
typeof :
Used to obtain the System.Type object for a type. A typeof expression takes the following form:System.Type type = typeof(int);
You could have find more info on MSDN. :)
-KR
这篇关于新旧之间的区别传递对象的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!