1、什么是单例
官方定义:确保一个类只有一个实例,并提供一个全局访问点
#### 2、编写一个单例(Singleton)类。把构造函数设置为private,设置一个public、static的对象实例
public FileManager{
private FileManager(){}
public readonly static FileManager Instance=new FileManager();
}
3、什么是mvc
● Model(模型)是应用程序中用于处理应用程序数据逻辑的部分。通常负责在数据库中存取数据。
● View(视图)是应用程序中处理数据显示的部分。通常是依据模型数据创建的。
● Controller(控制器)是应用程序中处理用户交互的部分。通常负责从视图读取数据,控制用户输入,并向模型发送数据。
4、什么是restful风格
一种软件架构风格、设计风格,而不是标准,只是提供了一组设计原则和约束条件。它主要用于客户端和服务器交互类的软件。基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存等机制。
5、给定义一个模型数组Arr,请在数组中找出最大的数,并输出这个数字(遇到过)
int[] array = new int[] { 1,2,4,3,0,-1,34,545,2,34};
Console.WriteLine("--------------Array自身方法-----------------");
Console.WriteLine("Min:{0}",array.Min()); //最小值
Console.WriteLine("Max:{0}", array.Max()); //最大值
Console.WriteLine("Average:{0}", array.Average()); //平均值
6、取最后一个值或arry最大值(遇到过)
int[] array = new int[] { 1, 2, 4, 3, 0, -1, 34, 545, 2, 34 };
Console.WriteLine("max{0}",array.Max());
int lenth = array.Length;
string str = (array[lenth - 1]).ToString();
Console.WriteLine("最后一个值{0}", str);
Console.ReadKey();
7、使用代码编写寻找最小值
7.1 最小值(遇到过)
/// <summary>
/// 最小值
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
public static int Min(int[] array)
{
if (array == null) throw new Exception("数组空异常");
int value = 0;
bool hasValue = false;
foreach (int x in array)
{
if (hasValue)
{
if (x < value) value = x;
}
else
{
value = x;
hasValue = true;
}
}
if (hasValue) return value;
throw new Exception("没找到");
}
7.2、使用代码编写寻找最大值
/// <summary>
/// 最大值
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
public static int Max(int[] array)
{
if (array == null) throw new Exception("数组空异常");
int value = 0;
bool hasValue = false;
foreach (int x in array)
{
if (hasValue)
{
if (x > value)
value = x;
}
else
{
value = x;
hasValue = true;
}
}
if (hasValue) return value;
throw new Exception("没找到");
}
7.3、平均值
/// <summary>
/// 最大值
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
public static int Max(int[] array)
{
if (array == null) throw new Exception("数组空异常");
int value = 0;
bool hasValue = false;
foreach (int x in array)
{
if (hasValue)
{
if (x > value)
value = x;
}
else
{
value = x;
hasValue = true;
}
}
if (hasValue) return value;
throw new Exception("没找到");
}
7.4、最终调用(遇到过)
static void Main(string[] args)
{
int[] array = new int[] { 1,2,4,3,0,-1,34,545,2,34};
Console.WriteLine("--------------Array自身方法-----------------");
Console.WriteLine("Min:{0}",array.Min());
Console.WriteLine("Max:{0}", array.Max());
Console.WriteLine("Average:{0}", array.Average());
Console.WriteLine("---------------内部实现方法------------------");
int min = Program.Min(array);
int max = Program.Max(array);
double? average = Program.Average(array);
Console.WriteLine("Min:" + min);
Console.WriteLine("Max:" + max);
Console.WriteLine("Average:" + average);
Console.Read();
}
8、请编程遍历页面上所有TextBox控件并给它赋值为string.Empty(遇到过)
foreach (System.Windows.Forms.Control control in this.Controls)
{
if (control is System.Windows.Forms.TextBox)
{
System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)control ;
tb.Text = String.Empty ;
}
}
9、SQL 查询重复出现次数最多的记录,按出现频率排序(SQL语句)
在有些应用里面,我们需要查询重复次数最多的一些记录,(遇到过)
SELECT keyword, count( * ) AS count
FROM article_keyword
GROUP BY keyword
ORDER BY count DESC
LIMIT 20
9.1、此段查询语句返回 article_keyword 表中 keyword 重复次数(count) 最多的20条记录。 (遇到过)
SELECT DISTINCT count( * ) AS count
FROM article_keyword
GROUP BY keyword
ORDER BY count DESC
LIMIT 6
此段查询语句返回 article_keyword 表中 keyword 的重复次数(count) 排名前 6 的数值。通过添加 DISTINCT 返回唯一记录。
以下同理也可实现:
将表A(交易ID,用户ID,交易额)中的用户交易额合计大于1000的用户进行合计交易额由大到小排序
10、写出一条 Sql 语句:取出表 A 中第 31 到第 40 记录(SQLServer,以自动增长的 ID 作为主键,注意:ID 可能不是连续的。
答:解 1:
select top 10 * from A where id not in (select top 30 id from A)
select top 10 * from a where id not in (select top 30 id from a)
10.1第二种解法 Row_NUMBER()函数
select * from (select ROW_NUMBER() over(order by t.ID) curr,t.* from tableA t) a where a.curr between 31 and 40
select * from (select ROW_NUMBER() over(order by t.ID) curr,t.* from tableA t) a where a.curr between 31 and 40
10.2、第二种解法:
select top 40 * from tableA except select top 30 * from tableA
select top 40 * from tablea except select top 30 * from tablea
11、C#编译原理 (已遇到)
C#的编译过程是从源代码开始的,通过IDE自带的编译器对源代码进行编译和检查,会生成托管模块,托管模块是可以多个或一个合成程序集,也就是我们常用的.dll和.exe文件,而程序集是不能自己执行的,所以必须要通过搭载在一个平台上进行运行, 这里就会用到CLR,CLR是一种虚拟机,它的其中一种功能就是加载程序集,然后在CLR上,会进行JIT编译,将IL编译成CPU指令。
过程中有几个重要的东西会在下面详细解释。
1.托管模块
2.CLR
3.JIT编译
12、 一列数的规则如下: 1、1、2、3、5、8、13、21、34求第30位数是多少, 用递归算法实现。(C#语言)
/// <summary>
/// 一列数的规则如下: 1、1、2、3、5、8、13、21、34求第30位数是多少, 用递归算法实现。(C#语言)
/// </summary>
/// <param name="pos"></param>
/// <returns></returns>
public int GetNumberAtPos(int pos)
{
if(pos==0||pos==1)
{
return 1;
}
int res = GetNumberAtPos(pos - 1) + GetNumberAtPos(pos - 2);
return res;
}
13、 C# string[] 字符串数组去重
string [] strs=new string[3];
strs[1]="0";
strs[2]="0";
strs[3]="1";
strs = strs.Distinct().ToArray();
14、 C# 数组去重
/// <summary>
/// 移除数组中重复数据
/// </summary>
/// <param name="array">需要除重的数组</param>
/// <returns>不重复数组</returns>
public static string[] DelRepeatData(string[] array)
{
return array.GroupBy(p => p).Select(p => p.Key).ToArray();
}
15、在一个由自然数1-1000中某些数字所组成的数组中,0数字可能出现的次数 (JS写法)
<script>
let n =0;
for(var i=0;i<=1000;i++)
{
const res=(i).toString().match(/0/g);
n+=res?res.length:0;
}
console.log(n);
alert(n);
</script>
16、在一个由自然数1-1000中某些数字所组成的数组中,0数字可能出现的次数 (C#写法)
public static int Number()
{
int a = 0;
for (int i = 0; i <= 1000; i++)
{
var res = i.ToString();
foreach (var item in res)
{
if (item=='0')
{
a++;
}
}
}
return a;
}
17、登录流程
可以参考简书: https://www.jianshu.com/p/228b2a07a413