日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

Javascript模拟c#中arraylist操作(学习分享)

發布時間:2025/3/15 C# 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Javascript模拟c#中arraylist操作(学习分享) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近在看javascript,在《javascript高級編程》中也學到了不少東西。但是在這里要感謝博客園的“湯姆大叔” 的無私奉獻,他的關于javascript相關博文也給我了很大的幫助。在此同時也要感謝 博客園中的“阿蔡”,在我上篇隨筆回復中提了相關建議!再次謝謝二位。

?

???? 在學習C#時候用到了ArrayList ,突然就想可不可以用javascript去模擬C#中ArrayList相關操作呢!C#中的ArrayList實例以后可以進行添加、移除、查找等操作。首先在此說明這個模擬操作的一些方法時候沒有考慮執行效率相關問題,只是報著學習的態度去嘗試。

?

? 在此就分享相關代碼,有什么不妥的地方希望各位高手斧正。謝謝。

?

?

/*

* javascript模擬C#中的arraylist
* 心傷煙雨

* QQ:909507090

* [url]www.qhjsw.net[/url]

* 更新時間:2012-02-24

*/

function ArrayList() {

this.length = 0;

this.array = new Array();

//獲得指定索引的值
this.Item = function (index) {

return this.array[index];

}

//添加新項
this.Add = function (value) {

this.array[this.length] = value;


this.length++;

}

//移除
this.Remove = function (value) {

if (this.length >= 1) {

for (var i = 0; i < this.length; i++) {

if (this.array[i] == value) {

for (var j = i; j < (this.length - 1); j++) {

this.array[j] = this.array[j + 1];

}

this.length--;

this.array[this.length] = null;

this.array.length--;

break;

}

}

}

else {

this.length = 0;

}

}
//插入

this.Insert = function (value, index) {

if (index < 0) { index = 0; }


if ((this.length >= 1) && (index <= this.length)) {

for (var i = this.length; i > index; i--) {

this.array[i] = this.array[i - 1];

}


this.array[index] = value;


this.length++;

}

else {

this.Add(value);

}

}
//判斷指定的值是否存在

this.Exist = function (value) {

if (this.length > 1) {

for (var i = 0; i < this.length; i++) {

if (this.array[i] == value) {

return true;

}

}

}


return false;

}

//清空
this.Clear = function () {
//感謝 “阿蔡” 的建議 謝謝 。
this.array.length = 0;

this.length = 0;

}


this.GetArray = function () {

return this.array;

}

//長度
this.Length = function () {

return this.length;

}

//導入
this.Import = function (splitString, splitChar) {

this.array = splitString.split(splitChar);


this.length = this.array.length;


}

//以指定分隔符導出,返回字符串
this.Export = function (joinChar) {

var strReturn = "";


if (this.length >= 1) {

for (var i = 0; i < this.length; i++) {

strReturn += this.array[i];


if (i < (this.length - 1)) {

strReturn += joinChar;

}

}

}

return strReturn;


}

}

如果有任何有助于我提高的還請各位大俠提出相關建議,我會加以學習和改正。希望共同與大家一起交流和學習。在此謝過。?

?

?

?

轉載于:https://www.cnblogs.com/bluescreen/archive/2012/02/25/2368216.html

總結

以上是生活随笔為你收集整理的Javascript模拟c#中arraylist操作(学习分享)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。