C#使用自定義算法對數(shù)組進(jìn)行反轉(zhuǎn)操作的方法
更新時間:2015年04月06日 16:54:47 作者:令狐不聰
這篇文章主要介紹了C#使用自定義算法對數(shù)組進(jìn)行反轉(zhuǎn)操作的方法,涉及C#針對數(shù)組操作的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了C#使用自定義算法對數(shù)組進(jìn)行反轉(zhuǎn)操作的方法。分享給大家供大家參考。具體如下:
C#的Array對象自帶反轉(zhuǎn)功能,但是下面的代碼完全通過自定義的算法來實現(xiàn)數(shù)組反轉(zhuǎn)
復(fù)制代碼 代碼如下:
public static void ReverseArray<T>(this T[] inputArray)
{
T temp = default(T);
if (inputArray == null)
throw new ArgumentNullException("inputArray is empty");
if (inputArray.Length > 0)
{
for (int counter = 0; counter < (inputArray.Length / 2); counter++)
{
temp = inputArray[counter];
inputArray[counter] = inputArray[inputArray.Length - counter - 1];
inputArray[inputArray.Length - counter - 1] = temp;
}
}
else
{
Trace.WriteLine("Reversal not needed");
}
}
{
T temp = default(T);
if (inputArray == null)
throw new ArgumentNullException("inputArray is empty");
if (inputArray.Length > 0)
{
for (int counter = 0; counter < (inputArray.Length / 2); counter++)
{
temp = inputArray[counter];
inputArray[counter] = inputArray[inputArray.Length - counter - 1];
inputArray[inputArray.Length - counter - 1] = temp;
}
}
else
{
Trace.WriteLine("Reversal not needed");
}
}
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
C#操作IIS程序池及站點的創(chuàng)建配置實現(xiàn)代碼
最近在做一個WEB程序的安裝包;對一些操作IIS進(jìn)行一個簡單的總結(jié);主要包括對IIS進(jìn)行站點的新建以及新建站點的NET版本的選擇,還有針對IIS7程序池的托管模式以及版本的操作2013-03-03詳解C#使用AD(Active Directory)驗證內(nèi)網(wǎng)用戶名密碼
這篇文章主要介紹了詳解C#使用AD(Active Directory)驗證內(nèi)網(wǎng)用戶名密碼的相關(guān)資料,希望通過本文能幫助到大家,讓大家實現(xiàn)這樣的功能,需要的朋友可以參考下2017-10-10