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();
}
}
}
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();
}
}
}
相关文章推荐
- 黑马程序员——IO的使用
- 黑马程序员——Java错误笔记——static
- 2015实习求职总结
- 2015摩根士丹利(Morgan Stanley)实习电话面试
- 黑马程序员——集合框架详解
- 程序员面试内容
- 微软100题(45)几道雅虎面试题
- 微软100题(44)几道腾讯面试题
- 面试题22:栈的压入弹出序列
- 个人发展(职业规划)
- 面试题21:包含min函数的栈
- 面试题之final,finally和finalize的区别以及如果catch里面有return语句,请问finally里面的代码还会执行吗?
- 求职-如何伪装一份cs的简历
- [程序员短壁纸]2015年05月
- 黑马程序员——java面向对象-继承
- 黑马程序员——内部类
- 黑马程序员——OC 基础:实例变量修饰符,description方法和多态
- 面试题:将一个数用二进制打印输出…
- Andorid工程师的职业生涯
- 【黑马程序员】----java基础---面向对象