我可以从c#.net中的char数组中删除char元素吗? [英] Can I remove a char element from char array in c# .net?

查看:120
本文介绍了我可以从c#.net中的char数组中删除char元素吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从c#.net中的char数组中删除char元素吗?如果可以,请告诉我怎么做?

Can I remove a char element from char array in c# .net? If I can please tell how to do it?

推荐答案

我认为要删除array 中的一个元素,其他元素必须是shifted ,并且数组必须具有要使用Array.Resize方法调整大小,请在此处 http://msdn.microsoft.com/en-us/library/bb348051.aspx [ ^ ],其中提到此方法分配具有指定大小的新数组,将元素从旧数组复制到新数组,然后用新数组替换旧数组.

或者,由于字符串类表示character array的连续元素,因此在 http://www.msdn.com/zh-cn///msdn.microsoft.com/zh-CN/library/d8d7z2kk.aspx [
I think to remove an element of an array other elements have to be shifted and the array has to be resized using Array.Resize method explained here http://msdn.microsoft.com/en-us/library/bb348051.aspx[^] at which it is mentioned that This method allocates a new array with the specified size, copies elements from the old array to the new one, and then replaces the old array with the new one.

Alternatively, since the string class represents contiguous elements of a character array, its Remove method explained here http://msdn.microsoft.com/en-us/library/d8d7z2kk.aspx[^] can be used as follows:
char[] chars = new char[]{'c','h','a','r','s'};
char[] trimmedChars = new string(chars).Remove(1,1).ToCharArray();
/* Contents of trimmedChars
c 
a 
r 
s 
*/


这些链接可能对您有帮助
http://stackoverflow.com/questions/496896/how-to-delete-an-element-from-an-array-in-c-sharp [ http://stackoverflow.com/questions/1343934/最快的实现方式重复字符删除字符串中的字符串c [
These links may help you
http://stackoverflow.com/questions/496896/how-to-delete-an-element-from-an-array-in-c-sharp[^]
http://stackoverflow.com/questions/1343934/fastest-way-to-implement-duplicate-character-removal-in-string-c[^]


这篇关于我可以从c#.net中的char数组中删除char元素吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆