可能重复:
为什么使用迭代器而不是数组索引?
我正在回顾我对C++的了解,我偶然发现了迭代器.我想知道的一件事是什么让它们如此特别,我想知道为什么:
using namespace std;
vector<int> myIntVector;
vector<int>::iterator myIntVectorIterator;
// Add some elements to myIntVector
myIntVector.push_back(1);
myIntVector.push_back(4);
myIntVector.push_back(8);
for(myIntVectorIterator = myIntVector.begin();
myIntVectorIterator != myIntVector.end();
myIntVectorIterator++)
{
cout<<*myIntVectorIterator<<" ";
//Should output 1 4 8
}
Run Code Online (Sandbox Code Playgroud)
比这更好:
using namespace std;
vector<int> myIntVector;
// Add some elements to myIntVector
myIntVector.push_back(1);
myIntVector.push_back(4);
myIntVector.push_back(8);
for(int y=0; y<myIntVector.size(); y++)
{
cout<<myIntVector[y]<<" ";
//Should output 1 4 8
}
Run Code Online (Sandbox Code Playgroud)
是的,我知道我不应该使用std命名空间.我刚把这个例子从cprogramming网站上删除了.那么请你告诉我为什么后者更糟?有什么大不同?
在头文件中包含头文件与在实现文件中包含头文件有什么区别?
这个
例如:
// test.h
#include"globals.h"
class Test
{
Test();
};
Run Code Online (Sandbox Code Playgroud)
VS
//test.cpp
#include"globals.h"
Test::Test()
{
}
Run Code Online (Sandbox Code Playgroud) 目前,我有一个类组件,其中包含充当JSX中组件的功能。
例:
class MyComponent extends React.Component {
MySubComponent = (props) => {
if (props.display) {
return <p>This text is displayed</p>
}
}
render() {
return (
<this.MySubComponent display={true} />
)
}
}
Run Code Online (Sandbox Code Playgroud)
这样调用组件有什么影响吗?还有一个术语吗?
我不认为我正确理解MVVM模式,因为拥有Model和ViewModel类对我来说似乎是多余的.
我对模型的理解是基本上添加一个类的次要细节,让ViewModel处理所有的逻辑和实现.如果是这样的话,为什么将两者分开呢?难道你不能在视图模型中创建变量,属性等,并且仍然有逻辑吗?
对我来说,它在某种程度上听起来像C++.您有头文件,它描述了定义类的类和实现文件.在c#中这样做有什么意义吗?
我觉得我不理解分离,因为我不完全理解MVVM模式.如果有人可以为我澄清这将是非常棒的.
提前致谢.
我创建了一个属性,用于定义哪些属性具有"特殊"数据.我的属性看起来像这样:
[AttributeUsage(AttributeTargets.Property)]
public class TestAttribute : Attribute
{
}
Run Code Online (Sandbox Code Playgroud)
我不需要在类的主体中有任何东西,因为它所做的只是识别属性.这是不好的做法吗?如果是这样,有什么更好的选择?
好的,我有这个代码,我知道它不是很好的编程实践.我忘记了它的名字.
int main()
{
int variable;
{
int variable;
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个本地命名空间还是什么?我只是记不起这样做的正确用语.
目前我正在使用.Net 3.5所以请告诉我它是否已在以后的版本中修复.
目前我有2种方法,具有以下签名:
void Method1(string, string)
void Method1(string, params string[])
Run Code Online (Sandbox Code Playgroud)
如果我打这样的电话
Method1("test1", "test2")
Run Code Online (Sandbox Code Playgroud)
编译器如何知道调用哪个方法?为什么.Net允许这个?
我假设在IL中,生成的代码是不同的,因此允许,但它不应该,因为你可以得到意想不到的结果.是否允许这样做有充分的理由吗?
提前致谢.
c# ×3
c++ ×3
.net ×1
ambiguous ×1
attributes ×1
c++11 ×1
components ×1
header ×1
indexing ×1
iterator ×1
javascript ×1
loops ×1
methods ×1
mvvm ×1
namespaces ×1
react-props ×1
reactjs ×1
reflection ×1
scope ×1
signature ×1
this ×1
viewmodel ×1
wpf ×1