您的位置:首页 > 职场人生

C#面试常见题目源代码汇总

2015-05-31 15:07 513 查看
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections;

namespace InterviewTest

{

class Program

{

static void Main(string[] args)

{

#region

////把分拣基数、偶数的联系用集合实现。int []nums ={1,2,3,4,5,6,7,8,9};基数在左边,偶数在右边

//int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

//List<int> listJI = new List<int>();

//List<int> listOU = new List<int>();

//for (int i = 0; i < nums.Length; i++)

//{

// if (nums[i] % 2 == 0)

// {

// listOU.Add(nums[i]);

// }

// else

// {

// listJI.Add(nums[i]);

// }

//}

//listJI.AddRange(listOU);

//foreach (var item in listJI)

//{

// Console.Write(item + " ");

//}

#endregion

#region

////将int数组中的基数放到一个新的int数组中返回。

////将数组中奇数取出来放到放到一个集合中,最终将集合转换成数组

//int[] nums = { 1, 2, 4, 5, 3, 6, 7, 8, 9 };

//List<int> listJS = new List<int>();

//for (int i = 0; i < nums.Length; i++)

//{

// if (nums[i] % 2 != 0)

// {

// listJS.Add(nums[i]);

// }

//}

//int[] numsNew = listJS.ToArray();

//for (int i = 0; i < numsNew.Length; i++)

//{

// Console.Write(numsNew[i] + " ");

//}

#endregion

#region

////从一个整数的List<int>中找出最大值,最小值

//List<int> list = new List<int>() { 531, 2, 4, 5, 6, 7, 8, 3, 12, 53, 22, 63, 12, 63, 13, 74, 234 };

//int max = int.MinValue;

//int min = int.MaxValue;

//for (int i = 0; i < list.Count; i++)

//{

// if (list[i] > max)

// {

// max = list[i];

// }

// if (list[i] < min)

// {

// min = list[i];

// }

//}

//Console.WriteLine("531, 2, 4, 5, 6, 7, 8, 3, 12, 53, 22, 63, 12, 63, 13, 74, 234中\r\n最大值是:{0},最小值是:{1}", max, min);

#endregion

#region

////把123转换为壹贰叁 0零 1壹 2贰 3叁 4肆 5伍 6陆 7柒 8捌 9玖

//Console.WriteLine("请输入一个整数:");

//string strinput = Console.ReadLine();

//string str = "0零 1壹 2贰 3叁 4肆 5伍 6陆 7柒 8捌 9玖";

//string[] strNew = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

//string strNews = "";

//Dictionary<char, char> dic = new Dictionary<char, char>();

//for (int i = 0; i < strNew.Length; i++)

//{

// dic.Add(strNew[i][0], strNew[i][1]);

//}

//for (int i = 0; i < strinput.Length; i++)

//{

// if (dic.Keys.Contains(strinput[i]))

// {

// Console.Write(dic[strinput[i]]);

// }

// else

// {

// Console.Write(strinput[i]);

// }

//}

#endregion

#region

////计算字符串中每个字符出现的次数,不区分大小写"Welcome to chinese"

//string str = "Welcome to Chinese";

//Dictionary<char, int> dic = new Dictionary<char, int>();

//int count = 0;

//for (int i = 0; i < str.Length; i++)

//{

// if (str[i] == ' ')

// {

// continue;

// }

// if (dic.Keys.Contains(str[i]))

// {

// count++;

// }

// else

// {

// dic[str[i]] = 1;

// }

//}

//foreach (KeyValuePair<char, int> kv in dic)

//{

// Console.WriteLine("字母{0}出现了{1}次", kv.Key, kv.Value);

//}

#endregion

#region

//把两个ArrayList集合{"a","b","c","d","e"}和{"d","e","f","g","h"}把这两个集合去除重复项后合并为一个集合

ArrayList listOne = new ArrayList() { "a", "b", "c", "d", "e" };

ArrayList listTwo = new ArrayList() { "d", "e", "f", "g", "h" };

for (int i = 0; i < listOne.Count; i++)

{

if (!listTwo.Contains(listOne[i]))

{

listTwo.Add(listOne[i]);

}

}

for (int i = 0; i < listTwo.Count; i++)

{

Console.Write(listTwo[i] + " ");

}

#endregion

Console.ReadKey();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: