C#.docx
《C#.docx》由会员分享,可在线阅读,更多相关《C#.docx(30页珍藏版)》请在冰豆网上搜索。
C#
Clr(commonlanguageruntime)
IL(intermediatelanguage)
MSIL(microsoftintermediatelanguage)
第二章:
C#简介
第三章:
基础
Classclassname
{console.writeline(“”);
Return0;
//classbody
}
Pubilic:
任何地方访问static:
静态
C#Main()
Javamain()
Vb6SubMain()
类型:
int,char,float,string货币:
decimal
Bool/long都是值类型
例2:
(49页)
Usingsystem;
Classrestangle
{
publicintwidth;
Publicintheight;
}
Structvaltyperectangle
{
publicintWidth;
PublicintHeight;
}
PublicstaticintMain()
{restanglerect1=newrestangle();
Rect1.Width=10;
Rect1.Height=15;
Restanglerect2=rect1;
Console.Writeline(“”);}
3.3C#预定义
System.int32x;
明天55页。
引用类型:
system.object-----Equals(),gethashcode(),gettype().,tostring().搭配
System.string-----stringfilepath=@”c:
\prp\fisft.cs等价于-stringfilepath=”c:
\\prp\\fisft.cs
值类型:
struct结构主要是NEW
枚举:
enum
接口:
委托:
类:
数组
长度:
length,getlength(0)Array.sort(string)数组升序排列,Array.reverse(string)降序排列
支持隐形转换:
int.parse(s);
Readonly:
只读变量。
常量:
在变量前加const就能把它变成常量。
Checkedunchecked检查运算符.字值溢出处理
Is可以检查特定类型兼容。
Sizeof确定所要值空间长度:
值为4字节
Tyepof(7ORH)返回字符类型
USING语句:
异常处理:
Try,Catch,
Finally(92页)
方法:
命名空间:
namespace(100页)
GetNamespace()和GetTYPE()方法来处理及区别。
Main()
PublicstaticintMain()/publicstaticvoidMain()的用法。
(带参数的用法:
数组):
文件类型:
.exe控制台应用程序。
. Library类库。
.module没有清单的组件。
.winexeWindows应用程序.
IO
控制台的输入:
Console.Writeline((char)x);console.writeline(s)///////intx=console.read();intx=console.readline();
输出:
console.write()//console.writeline();
0是参数索引,4是宽度值。
第四章:
类/继承
方法:
IsPasswordCorrect(x,y)///ChangePassword(x,y)的使用
方法:
SetMinPasswordLength()///GetMinPasswordLength();的使用
Getset方法
131页。
155页
方法:
CalculatePrice()返一个十进制小数。
Base关键字。
OOP程序结构:
第五章面向对象的C#语言
定义重载的方法:
VirtualvoidRecordCall();
PublicvoidDoSomething(intx,inty)方法重载
构造函数:
Const/readonlybase/this关键字的用法。
Dispose()/close()方法,finaliza()方法:
。
三个结合使用。
Idisposable是在继承Dispose()方法时用。
5.4结构。
5接口:
Interfacename;方法:
MoveNext()移动到下一个项目;Reset()返回第一个项目
PutOn()方法/Takeoff()方法Ijumper是表示一个接口。
接口的继承:
interfaceIsweatshirt:
Ijumper{boolHoodUp{get;set;}};
第六章:
C#的高级论题
异常处理:
Systerm.Exception;
Try…正常操作部分…..catch(MyExceptione)…处理各种错误代码……finally执行的其它操作。
overflowException()两大溢出方法IndexOutOfRangeException()
属性:
HelpLink,Message,sourse,stacktrace,targetSite.
coldcallfileReader类
委托:
intI=int.Parse(“99”)
关键字:
delegate如:
delegatedoubleTwolongsOp(x,y);
#define/#undef删除符号的定义。
#warning#error#region#endregion#line处理器指令
属性
Conditional,DIIImport,Obsolete.
指针:
unsafe/void&取地址运算符*取地址的内容。
Sizeof运算符
第294页的指针。
第7章基类
System.Object.
方法:
stringToString(),intGetHashTable(),boolEquals()
298页
比较测试两个(x,y)引用是否指向类的相同内存地址:
ReferenceEquals(x,y)
Equals(X,Y)是比较值性的。
==比较运算符。
System.String
Append()方法:
代替的作用。
StringBuilder属性LengthCapacity只读属性MaxCapacity
Stringpattern=@”\bn”它是指查找n为开头的,Stringpattern=@”ion\b”它是指查找以ion结尾的播音字符。
WriteMatches()方法
数组列表:
System.Collection.ArrayList
GetEnumerator()方法
属性:
AttributeUsage()
Type的属性:
name,fullName,Namespace
对象的引用相关类:
BaseType,UndertyingSystemType
Type的方法:
Assembly类它的一个静态方法:
GetCustomAttritutes()
Thread线程
ThreadDepthChangeThread=newThread()Thread.Start()方法来启动线程。
DepthChangeThread.Resume()恢复线程,DepthChangeThread.Abort()取消线程
DepthChangeThread.Suspend()响应线程。
Sleep()方法。
DisplayNumbers()累加一个数字,并显示每加一个进程。
第八章在.net环境下编程
MSDN帮助:
如果选择某个关键字,按F1出现帮助文档。
(382页)组装工程
第九章windows应用程序
类:
System.Drawing画笔,字体,图标,其它图形对象的类。
System..Data控件数据。
Application.Run();方法处理操作程序
窗体:
MDI是一个多文档窗体,属性:
IsMDIContainer=ture是可以创建窗体。
DesktopLocation:
位置;
BorderStyle窗体大小,MinmizeBox窗体的最小化MaximizeBox窗体的最大化ForeColor字体的前景色。
SetDesktopLocation:
定位窗体。
ShowDialog窗体显示模式对话框。
控件:
System.Windows.Forms.Control
TextBox控件TrackBar控件
事件
组合控件:
GroupBox
System.Drawing.Drawing2D,System.Drawing.ImagingSystem.Drawing.Text.
1..UsingSystem.Drawing;例PointSizeRectangle;
2.System.Drawing.Drawing2D画笔:
Brush派生类:
SolidBrush,TextureBrush,RectangleGradientBrush.
3.钢笔:
penDashStyle属性可以指定几种类型的虚线。
4.字体System.Drawing有三种字体:
Monospace,SansSerif,Serif
5.图形System.Drawing.Graphics
定制控件:
System.Windows.Forms.UserControl类Bezier显示器。
OnPainBackground()方法:
描绘定制绘图的背景。
yTrackBar_Scroll()事件。
菜单:
System.Windows.Forms.MainMenu/MenuItem/ContextMenu.
方法:
aboutForm.ShowDialog();它的返回值:
DialogResult.OK保存数据:
SaveFileDialog()类
*.Filter=”htmlfile(*.html)|*.html|Allfiles”
menuItemFileExit_Click(){this.Close}
第10章装配件
第11章数据访问
共享类:
DataSet:
包含DataTable,用于断开链接;DataTable:
由多个DataCloumn组成;DataRow:
数据一行;DataCloumn:
数据列DataRelation:
DataSet和DataTables之间的连接Constaint:
为列定义规则。
DataColumnMapping:
用DataTable中的列名映射DataTableMapping表名映射;
特定类:
SqlCommand,OleDbCmmand:
SQL的包装和过程调用。
sqlconmmandBuilderoledbCommandBuilder用于SELECT子句生成SQL语句的类
sqlConnectionOleDbConnection:
用于数据连接
SQLdataAdapterOleDbDataAdapter用于存储,插入,更新,删除的语句的类
sqlDataReaderOLEDBdataREADER只向前的连接数据读取器
常用于用户登陆,用:
if(reader.HasRows){判定它们的行数}
SqlParameterOleDbParameter为存储过程定义一个参数;
SqlTransactionOleDbTransaction一个数据库处理事务
ReadCommitted:
这个级别是在第二个事务处理中才能访问第一个事务处理写入数据
ReadUncommitted:
任何时间都可以对这个事务生理中写入数据。
RepeatableRead:
ReadUncommitted的扩充
Serializable:
数据访问的最高级别
命名空间:
System.Data:
数据访问类;System.Data.Common共享的类;Systerm.Data.OleDb:
;System.Data.SqlClient;System.Data.SqlTypes:
数据类型
连接:
Stringsource=”serve=(local)\\NetSDK;”+”uid=QSUser;pwd=QSPassword;”+”database=Northwind”;
系统登陆的字符方法:
datasource=.;InitialCatalog=数据库名称;IntegratedSecurity=true;
查找字符时:
where条件里面的字符串常量需要加'号
"selectid,namefromuser1wherename='"+textBox1.Text.Trim()+"'andid='"+textBox2.Text.Trim()+"'"
SqlConnectionconn=newSqlConnection(source)
Conn.Open();
SqlTransactiontx=conn.BejinTransaction();
Tx.Commit();
Conn.Close();
属性:
StoredProcedure:
cmd.CommandType=CommandType.StoreProcedure
TableDirect:
cmdCommandType=CommandType.TableDirect;
执行命令:
ExecuteNonQuery不返加任何结果用于更新最好
ExecuteReader返回一个类型化DataReader/OLEDBDataReader用于输出
ExecuteScalar返回一个值
ExecuteResultset为将来使用而保留(少用,容易出错)
ExecuteXmlReader:
返回一个XmlReader
调用:
1.更新:
2.删除:
3插入:
数据读取器:
DataReader:
可以读取多条记录,且可显示出来
综合实例:
数据集:
DataSet
DataColumn数据列
属性:
数据行
AcceptChanges方法;在DataRow中数据最常见的用法:
BeginEdit()和EndEdit()方法
模式的生成:
SqlDataAdapterda=newSqlDataAdaper(select,conn);
DataSetds=newDataSet();
da.Fill(ds,”Customers”);
数据的关系:
GetParentRows(返回有0行或多行的数据)GetParentRow(根据某个给定的关系检索一个父行);
数据的约束:
:
XML模式:
6.2,保存对数据集的修改。
SqlDataAdapter最有可能包含:
SelectCommand,还可以定义InsertCommand,UpdataCommand,OleDbCommand实例。
第一种是调用NewRow()函数,返回一个空行,然后向其填充数据,最好后把它添加到Rows集合中;第二种是把一组数据传判送给Rows.Add():
删除行:
Delete()方法;
使用ADO
DataSetsource={somedataset};数据合并DataSetdest=source.Clone();//DataSet复制dest=source.copy()
修改:
DataSetdest=source.GetChanges();
SQLServer生成:
第十二章:
.net数据
DataGrid控件:
方法1:
SetDataBinding(数据源,显示的表名/null);方法2:
DataTable();
方法3:
DataView(表)只允许修改要显示的数据列,不显示数据行;{AllowEdit=false表示在数据行上禁用所有功能;AllowNew=false表示禁用新行功能;AllowDelete=false表示禁用删除行功能;RowStateFilter只显示指定状态的行;RowFilter可滤数据行;}
方法4:
DataSetorDataViewManager();方法5:
IlistSource;Ilist()来显示数据。
单击列排序代码如:
连接数据的关键点:
dataGrid1.SetDataBinding(ds说明{DataSetds=newDataSet();},”Customers(表名)”);
DataViewManager和DataSet中所显示的数据一样;
接口对象IlistSource成员GetList(),它返回一个Ilist接口,而Ilist就可以执行多个类
层次结构:
Alignment:
表示列中的数据对齐方式;FontHeight:
字体值;HeaderText:
:
显示标题的文本;
MappingName在屏幕上显示的DataTable的列;NullText显示文本;PropertyDescriptor:
ReadOnly只读;Width宽度;
数据绑定:
1.简单的TextBox的数据绑定:
DataSetds=CreateDataSet();
Textbox.DataBings.Add(“Text”,ds,”Products.ProductName”);
2.数据绑定对象:
textbox.DataBindings.Add(“Text”,ds,”Products.ProductName”);
1.BindingContext属性;可以包含几个数据源(CurrencyManager/PropertyManager)
2.Binding类
3CurrencyManager/PropertyManager定义当前记录在数据源中的位置,在改变当前记录时,需要调整所有的ListBindings.如图
548页
VS自带的数据访问:
OleDbConnection或SQLConnection来创建数据库连接;
模块:
openFileDialog
{openFileDialog1.ShowDialog();
stringopenfile=this.openFileDialog1.FileName;
if(openfile.Trim()=="")
{return;}
else
{richTextBox1.LoadFile(openfile,RichTextBoxStreamType.PlainText);}
}
saveFileDialog
{
saveFileDialog1.Filter="文本文件(*.txt)|*.doc|Allfile(*.*)";
saveFileDialog1.InitialDirectory=@".e:
\";
this.saveFileDialog1.ShowDialog();
stringsave=this.saveFileDialog1.FileName;
if(save.Trim()=="")
{
return;
this.richTextBox1.SaveFile(save,RichTextBoxStreamType.PlainText);
}
}
剪切:
{this.richTextBox1.Cut();}
复制:
{this.richTextBox1.Copy();}
粘贴:
{this.richTextBox1.Paste();}
toolBar工具的应用:
{
privatevoidtoolBar1_ButtonClick(objectsender,System.Windows.Forms.ToolBarButtonClickEventArgse)
{//响应工具栏按钮单击事件
if(e.Button==this.toolBarButton1)
{//新建文件
this.richTextBox1.Text="";
}
if(e.Button==this.toolBarButton2)
{//打开文件
this.openFileDialog1.ShowDialog();
stringStrFileName=this.openFileDialog1.FileName;
if(StrFileName.Trim()=="")
return;
try
{
this.richTextBox1.LoadFile(StrFileName,RichTextBoxStreamType.PlainText);
}
catch(ExceptionError)
{
MessageBox.Show("文件格式无效,可先新建一个文档,保存后再打开测试!
","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
if(e.Button==this.toolBarButton5)
{//剪切文本
this.richTextBox1.Cut();
}
if(e.Button==this.toolBarButton6)
{//复制文本
this.richTextBox1.Copy();
}
if(e.Button==this.toolBarButton7)
{//粘贴文本
this.richTextBox1.Paste();
}
}
statusBar状态工具
{privatevoidrichTextBox1_MouseMove(objectsender,System.Windows.Forms.MouseEventArgse)
{//检测鼠标的位置
intxPos=Cursor.Position.X;
intyPos=Cursor.Position.Y;
this.statusBarPanel2.Text="鼠标位置:
X="+xPos.ToString()+"Y="+yPos.ToString();
}
}
托盘显示:
notifyIcon1跟contextMenu一起用;
{this.Visible=true;
this.notifyIcon1.Visible=true;
}
进度条:
progressBar
{intOneLevel=Int32.Parse(this.textBox1.Text);
intTwoLevel=Int32.Parse(this.textBox2.Text);
this.progressBar1.Maximum=OneLevel;
this.progressBar2.