125 Basic C# Interview Questions and Answers

英文原文:http://theprofessionalspoint.blogspot.jp/2013/10/125-basic-c-interview-questions-and.html

Below is the list of 125 basic C# interview questions with their answers. These C# interview questions and?answers?are very simple and straight-forward which cover the basic concepts of C# mostly related to object oriented concepts. So if you are preparing for C# interview, I will suggest you to must go through these 125 C# basic interview questions and answers to revise your C# concepts. Here goes the list of 125 basic C# interview questions and answers.

1. What is C#?

C# (pronounced “C sharp”) is a simple, modern, object-oriented, and type-safe programming language. It will immediately be familiar?to C and C++ programmers. C# combines the high productivity of Rapid Application Development (RAD) languages.

2. What are the types of comment in C#?

阅读更多

DataGrid绑定Dictionary问题

【问题】

在最近的项目中使用DataGrid的DataGridCheckBoxColumn绑定了后台TagModel类的IsSelected字段,数据源是TagModel类型的Dictionary,运行发现Checkbox不能正常勾选,提示错误:此视图不允许“EditItem”。

【问题重现】

前台:

1
<DataGridCheckBoxColumn Binding="{Binding IsSelected}" />
阅读更多

WPF之DragDrop拖放实例---图像资源管理器

1. 问题

在winform或wpf开发中,常会用到DragDrop拖放功能,如拖拽一个文件到程序窗体,则在文本控件上显示文件的路径,其他内容控件显示文件内容,这样省去输入文件路径或者打开文件对话框的麻烦。在实际应用中,我们也会看到一些影音播放器支持对拖放文件的播放,Office支持对拖放文件的插入等等。综合上述情况,多数情况下,我们关注了从程序外部拖放文件至程序,也就是拖过来。

那么如果现在做一个功能,需要我们把程序中的内容拖放到另一个程序中,比如直接拖拽程序中的图片控件到Word,就把图片控件中的图粘贴到Word中,也就是拖过去,这要怎么实现?

阅读更多

EntityFramework学习——EF开发模式

好久没写EF的东西,使用起来也觉得生疏,最近EF5发布,学习了一下新知识,总结一番。

1.Entity Framework架构原理回顾

什么是EF:EntityFrameWork是微软一个开源的ORM(对象关系映射)框架,是微软主推的数据存储技术,常用于构建数据存储层,使应用程序以对象模型的方式访问关系数据库的内容。

EF的架构和原理:EF的核心内容是EDM,具体可参考前一篇内容。可以理解为它是一个ADO.NET的增强版,它的底层是ADO.NET provider,上层则是应用程序,它提供了更灵活,更简单方便的数据存取方式。

EF的优点:它是一个开源框架,支持多种数据库(目前看来最稳定的是SQL Server,而Oracle的支持一直不太完美),将应用程序和数据库结构很好的分隔开,支持多种开发模式。

阅读更多

WordPress安装WP-DBManager出现警告的解决办法

给WP安装数据库备份工具WP-DBManager,完成后显示

Your backup folder MIGHT be visible to the public

To correct this issue, move the .htaccess file from wp-content/plugins/wp-dbmanager to /home/……/zcmhi.com/htdocs/wp-content/backup-db

可以用以下方式解决:

1.自制.htaccess  文件内容,该内容可在wp-content/plugins/wp-dbmanager/ 的htaccess  文件中找到。

阅读更多

wpf失去焦点事件中重获焦点

WPF 在TextBox失去焦点时检测数据,出错重新获得焦点解决办法
在WPF的TextBox的LostFocus事件中直接使用Focus()方法会出现死循环的问题
正确的使用方式有两种方法:
方法一:

1
2
3
4
5
6
7
8
9
10
11
private void textBox3_LostFocus(object sender, RoutedEventArgs e)
{
if (textBox3.Text != "abc")
{
this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Render,
new Action(() =>
{
textBox3.Focus();
}));
}
}

方法二,使用LostKeyboardFocus方法:

1
2
3
4
5
6
7
private void textBox3_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
if (textBox3.Text != "abc")
{
textBox3.Focus();
}
}

说明:在msdn上就查找到:

阅读更多

CreateBitmapSourceFromHBitmap内存泄露

用c#做图像处理的时候需要用到System.Drawing.Bitmap。在WPF中显示图像的Image控件接受的数据源是ImageSource,因此使用System.Drawing.Bitmap进行图像处理之后要把System.Drawing.Bitmap转换成ImageSource,转换方法如下:

1
2
3
4
5
6
7
System.Drawing.Bitmap m_Bitmap = new System.Drawing.Bitmap("c:temptest.jpg", false); 
IntPtr ip = m_Bitmap.GetHbitmap();
BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
ip, IntPtr.Zero, Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ip);
imageLarge.Source = bitmapSource;

其中DeleteObject的声明如下:

1
2
[DllImport("gdi32")]  
static extern int DeleteObject(IntPtr o);

使用过System.Drawing.Bitmap后一定要用DeleteObject释放掉对象,不然内存不释放,很快系统内存就消耗光了。

阅读更多

SQLServer中DateTime数据格式

在oracle中可以直接使用ToChar(getdate(),’yyyy-mm-dd’)

但在SQL Server 中需要以下的参数方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	
select CONVERT(varchar, getdate(), 120 )

2004-09-12 11:06:08

select CONVERT(varchar(12) , getdate(), 111 )

2004/09/12

select CONVERT(varchar(12) , getdate(), 112 )

20040912

select CONVERT(varchar(12) , getdate(), 102 )

2004.09.12

select CONVERT(varchar(12) , getdate(), 101 )

09/12/2004

select CONVERT(varchar(12) , getdate(), 103 )

12/09/2004

select CONVERT(varchar(12) , getdate(), 104 )

12.09.2004

select CONVERT(varchar(12) , getdate(), 105 )

12-09-2004

select CONVERT(varchar(12) , getdate(), 106 )

12 09 2004

select CONVERT(varchar(12) , getdate(), 107 )

09 12, 2004

select CONVERT(varchar(12) , getdate(), 108 )

11:06:08

select CONVERT(varchar(12) , getdate(), 109 )

09 12 2004 1

select CONVERT(varchar(12) , getdate(), 110 )

09-12-2004

select CONVERT(varchar(12) , getdate(), 113 )

12 09 2004 1

select CONVERT(varchar(12) , getdate(), 114 )

11:06:08.177

WPF调用Winform控件

WPF调用Winform控件实现主要分三步:

WPF调用Winform控件

1、添加两个引用:

WindowsFormsIntegration(负责整合WPF和Windows)
System.Windows.Forms

2、在 XAML文件中添加两个引用:

阅读更多