从数组中删除值?
我怎样才能取出这个数组的一行
array< array< int^ >^ >^ sample = gcnew array< array< int^ >^ >{
gcnew array<int>{0, 0, 0, 0, 0},
gcnew array<int>{1, 1, 1, 1, 1},
gcnew array<int>{2, 2, 2, 2, 2},
};
所以它会是:-
array< array< int^ >^ >^ sample = gcnew array< array< int^ >^ >{
gcnew array<int>{0, 0, 0, 0, 0},
gcnew array<int>{2, 2, 2, 2, 2},
};
Rajesh。
How can I take out one line of this array
array< array< int^ >^ >^ sample = gcnew array< array< int^ >^ >{
gcnew array<int>{0, 0, 0, 0, 0},
gcnew array<int>{1, 1, 1, 1, 1},
gcnew array<int>{2, 2, 2, 2, 2},
};
So it would be :-
array< array< int^ >^ >^ sample = gcnew array< array< int^ >^ >{
gcnew array<int>{0, 0, 0, 0, 0},
gcnew array<int>{2, 2, 2, 2, 2},
};
Rajesh.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然您可以使用 Array::Resize 来调整数组大小并使用 bachchan 提到的移位方法,但您通常不会在 C++/CLI 数组中添加或删除项目。
如果您需要从集合中动态添加或删除项目,请考虑使用
System::Collections::Generic::List
类型(请参阅 MSDN)。根据您对集合执行的操作,您可以使用更复杂的结构,例如
HashSet
或Dictionary
。While you can use
Array::Resize
to resize your array and use the shift method bachchan mentions, you generally don't add or remove items from a C++/CLI array.If you need add or remove items dynamically from a collection, look into using the
System::Collections::Generic::List<T>
type (see MSDN).Depending on what you're doing with the collection, you can use even more sophisticated structures, e.g.
HashSet<T>
orDictionary<K, V>
.for ( i = 0; i < n; i++ )
{
if ( a[i] == 目标 )
休息;
while
(++i < n )
a[i - 1] = a[i];
--n;
实际过程不包括删除步骤,只是移位步骤:
for ( i = 0; i < n; i++ )
{
if ( a[i] == target )
break;
}
while ( ++i < n )
a[i - 1] = a[i];
--n;
The actual process doesn't include a delete step, it's just the shift step: