被调试易程序运行完毕运行以下程序,并用注释的形式说明程序功能。

> 问题详情
编写C程序时通常为了提高可读性而加入注释,注释并不参与程序的运行过程。通常,编译程序在()阶段
悬赏:0&答案豆
提问人:匿名网友
发布时间:
编写C程序时通常为了提高可读性而加入注释,注释并不参与程序的运行过程。通常,编译程序在()阶段就会删除源程序中的注释。A.词法分析 B.语法分析 C.语义分析 D.代码优化请帮忙给出正确答案和分析,谢谢!
权威推荐: & &
为您推荐的考试题库
您可能感兴趣的试题
1某C语言程序中有表达式x%m(即x被m除取余数),其中,x为浮点型变量,m为整型非0常量,则该程序在(&)时会报错,该错误属于(&)错误。A.编译B.预处理C.编辑D.运行A.逻辑B.语法C.语义D.运行2在单CPU计算机系统中,完成相同功能的递归程序比非递归程序(&)。A.运行时间更短,占用内存空间更少B.运行时间更长,占用内存空间更多C.运行时间更短,占用内存空间更多D.运行时间更长,占用内存空间更少3已知函数f(). G()的定义如下所示,调用函数f时传递给形参x的值是5。若g(a)采用引用调用( call by reference)方式传递参数,则函数f的返回值为(&);若g(a)采用值调用(.call by value)的方式传递参数,则函数f的返回值为(&)。其中,表达式&X>>1&的含义是将x的值右移1位,相当于x除以2。A.35B.32C.11D.7A.35B.32C.11D.74设数组a[0.n-1,0..m-1](n&1,m&1)中的元素以行为主序存放,每个元素占用4个存储单元,则数组元素a[i,j](0&i&n,0&j&m)的存储位置相对于数组空间首地址的偏移量为 (&)。A.(j*m+i)*4B.(i*m+j)*4C.(j*n+i)*4D.(i*n+j)*4
我有更好的答案
请先输入下方的验证码查看最佳答案
图形验证:
验证码提交中……
找答案会员
享三项特权
找答案会员
享三项特权
找答案会员
享三项特权
选择支付方式:
支付宝付款
郑重提醒:支付后,系统自动为您完成注册
请使用微信扫码支付(元)
支付后,系统自动为您完成注册
遇到问题请联系在线客服QQ:
请您不要关闭此页面,支付完成后点击支付完成按钮
遇到问题请联系在线客服QQ:
恭喜您!升级VIP会员成功
常用邮箱:
用于找回密码
确认密码:【图片】程序调试经验集【程序员吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:105,238贴子:
程序调试经验集收藏
VC程序调试经验从拷贝来一个程序,1 拷贝过来的程序,如果程序的文字性说明没有写成注释的形式,编译将提示不认识的字符-error C2018, unknown character '0xd1', '0xa7', ...... 。 2 DOS的C语言下的语句-system("cls");
在VC下编译将不认识,如果system语句在100行,而101行是变量声明,则将提示101行有错,error C2143, 语法错误,missing ';' before 'type'。 3 如下语句 int choice,m; sum=read_message(); char a[4]="110",b[4];仍然提示C2143错误,我还没研究过全部代码中sum=read_message()这一句的标识符是否在某个地方定义过;改为: int choice,m; char a[4]="110",b[4]; sum=read_message();错误消失;该源代码经过改进上述2和3的问题,可以运行,这是一个DOS下不错的C程序;
程序员?来上市公司博为峰学软件技术,零基础授课,零元入学,就业有保障!程序员?学软件技术要学多久?学软件技术毕业起薪8K,入学即签就业协议!
网友说,用system("cls");清屏,记得包含stdlib.h, 我试了,不行;再包含windows.h,也不行。
但是取消system("cls")将不能清屏;找了一段C#代码,调试后该程序确实实现了清屏,通过调用Windows控制台API实现清屏,一共调用了四个API:GetStdHandle,GetConsoleScreenBufferInfo,SetConsoleCursorPosition,FillConsoleOutputCharacter。代码如下:using Susing System.Runtime.InteropSusing System.T namespace clears{
class StdHandleEnum
public const int STD_INPUT_HANDLE = -10;
public const int STD_OUTPUT_HANDLE = -11;
public const int STD_ERROR_HANDLE =-12;
coordinate.
internal struct COORD
public short X;
public short Y;
information
[StructLayout(LayoutKind.Sequential,
internal struct CONSOLE_SCREEN_BUFFER_INFO
public COORD S
public COORD p1;
[DllImport( "kernel32.dll ")] public
GetStdHandle(int
nStdHandle); [DllImport( "kernel32.dll ")] public
GetConsoleScreenBufferInfo(int
hConsoleOutput,
CONSOLE_SCREEN_BUFFER_INFO
lpConsoleScreenBufferInfo); [DllImport( "kernel32.dll ")] public
SetConsoleCursorPosition(int
hConsoleOutput,
dwCursorPosition); [DllImport( "kernel32.dll ",SetLastError=true,CharSet=CharSet.Auto)] public
FillConsoleOutputCharacter(int
hConsoleOutput,
cCharacter,
WriteCoord,
lpNumberOfCharsWritten); [STAThread] static
Main(string[]
CONSOLE_SCREEN_BUFFER_INFO
Console.Write( "Clear
"\r\nPress
key... ");
Console.ReadLine();
GetStdHandle(StdHandleEnum.STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hOut,
FillConsoleOutputCharacter(hOut,(short)' ',CSBI.Size.X*CSBI.Size.Y,Home,out CharOut);
SetConsoleCursorPosition(hOut,
Console.ReadLine(); } } }
学习了,谢谢楼主。
用C#作一个用户控件,按照以下教程:该控件的目的是显示日期时间,按照该文一步步进行,一切正常,但是建立测试项目后,添加控件的引用,在解决方案资源管理器中,右击测试项目的“引用”节点,添加用户控件的引用后,我并未在工具箱中发现自制的控件;然后在工具箱中右击任意一个控件,在弹出菜单中选择“选择项”,弹出“选择工具箱”对话框,选定刚才自写控件的DLL,再回到工具箱,自制控件出现;将自制控件添加到测试项目窗体上,运行,结果如下:
修改该控件,以便显示不同格式时间。增加一个私有变量private S以保存时间格式;增加一个公共属性public String Clockformat
} 在类的构造函数设置初始显示格式是默认格式;public ctlClock1(){
InitializeComponent();
format = ""; // 初始显示格式为默认格式} Timer控件中代码如下,根据用户设置的格式进行显示:protected virtual void timer1_Tick(object sender, EventArgs e)
if (format == "")
lblDisplay.Text = DateTime.Now.ToString();
DateTime DT1=DateTime.N
lblDisplay.Text = DT1.ToString(format, DateTimeFormatInfo.InvariantInfo);
} 打开测试项目,在窗体上放置四个自制控件,分别设置不同的显示格式,如下:private void Form1_Load(object sender, EventArgs e)
ctlClock12.Clockformat = "F";
ctlClock13.Clockformat = "R";
ctlClock14.Clockformat = "U";
} 运行,四个控件以不同格式显示日期时间,完成了C#下第一个脱离教程的自制控件;
做一个C#字符串操作演示程序。参考以下代码:然后用自己写的一个函数往窗体上输出字符串操作的结果;略作调试,完成了一些字符串操作的演示;没有写完所有字符串操作,写了几个,点不同的子菜单,就显示不同的操作结果,截个图:上代码:using Susing System.Collections.GponentMusing System.Dusing System.Dusing System.Lusing System.Tusing System.Windows.Fusing System.Text.RegularE namespace Str1{
public partial class Form1 : Form
public Form1()
InitializeComponent();
private void 字符串分割ToolStripMenuItem_Click(object sender, EventArgs e)
string mystring = "I like this food,are you?";
char[] separators = { ' ', ',', '?', ':', '!' };
int startpos = 0;
int endpos = 0;
int i = 0;
Draw1(mystring, 100, 100 - xg*2);
endpos = mystring.IndexOfAny(separators, startpos);
if (endpos == -1) endpos = mystring.L
if (endpos != startpos)
//Console.WriteLine(mystring.Substring(startpos, (endpos - startpos)));
Draw1(mystring.Substring(startpos, (endpos - startpos)), 100, 100+i*xg);
startpos = (endpos + 1);
i = i + 1;
} while (startpos & mystring.Length);
void Draw1(string str1, int xPos = 0, int yPos = 0)
SolidBrush aBrush = new SolidBrush(Color.Blue);
Font aFont = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Millimeter);
Graphics graphic = this.CreateGraphics();
graphic.DrawString(str1, aFont, aBrush, xPos, yPos);
void ClsFrm()
Graphics graphic = this.CreateGraphics();
graphic.Clear(this.BackColor);
private void 反转字符串ToolStripMenuItem_Click(object sender, EventArgs e)
string mystring = "一二三四五六七八九";
char[] mychars = mystring.ToCharArray();
Array.Reverse(mychars);
string mystring2 = new string(mychars);
Draw1(mystring, 100, 100);
Draw1(mystring2, 100, 200);
private void 提取子串ToolStripMenuItem_Click(object sender, EventArgs e)
string mystring = "My name is NDY.";
Draw1(mystring, 100, 100);
Draw1(mystring.Substring(3), 100, 200);
Draw1(mystring.Substring(11, 3),100,300);
private void 字符串比较ToolStripMenuItem_Click(object sender, EventArgs e)
string s1 = "aaaa";
string s2 = "aaaa";
//Compare( )method
//result值为“0”表示等,小于零表示 s1 & s2,大于零表示 s1 & s2
result = pare(s1, s2);
DrawCmp(result, 100, 100);
result = s1.CompareTo(s2);
DrawCmp(result, 100, 200);
result = pareOrdinal(s1, s2);
DrawCmp(result, 100, 300);
bresult = s1.Equals(s2);
bresult = String.Equals(s1, s2);
void DrawCmp(int r,int x,int y)
if (r == 0)
Draw1("s1等于s2", x, y);
else if (r & 0)
Draw1("s1小于s2", x, y);
Draw1("s1大于s2", x, y);
private void toolStripMenuItem2_Click(object sender, EventArgs e)
StringBuilder sb = new StringBuilder("I live the language");
Draw1(sb.ToString(), 100, 100);
Draw1("sb的长度是:" + sb.Length.ToString(), 100, 150);
sb.Length = 6;
Draw1(sb.ToString(), 100, 200);
private void isMatch方法ToolStripMenuItem_Click(object sender, EventArgs e)
string inputstring="Welcome to the ywicc,ywsmxy!";
if ( Regex.IsMatch( inputstring,"ywicc",RegexOptions.IgnoreCase) )
Draw1("Match Found",100,100);
Draw1(" No Match Found",100,100);
private void 用指定的字符串代替一个匹配模式ToolStripMenuItem_Click(object sender, EventArgs e)
string inputstring = "Welcome to the AAA!";
Draw1(inputstring, 100, 100);
string inputstring2 = Regex.Replace(inputstring, "AAA", "BBB");
Draw1(inputstring2, 100, 150);
再现技术贴
各位知道C语言经典程序中有字符图案的程序,如“100个经典C语言程序”中的例子7;[]现在想把它在C#中做出来;C代码如下:char a=176,b=219; printf("%c%c%c%c%c\n",b,a,a,a,b); printf("%c%c%c%c%c\n",a,b,a,b,a); printf("%c%c%c%c%c\n",a,a,b,a,a); printf("%c%c%c%c%c\n",a,b,a,b,a); printf("%c%c%c%c%c\n",b,a,a,a,b);} 转到C#中,就出现了一个问题,因为C#是强类型的语言,所以必须这么写:char a=(char)176;char b=(char)219; 否则编译器报错;摘录其中几个,在C#下做出,上图上代码:using Susing System.Collections.GponentMusing System.Dusing System.Dusing System.Lusing System.Tusing System.Windows.F namespace jdsmall1{
public partial class Form1 : Form
public Form1()
InitializeComponent();
private void 四个数的组合ToolStripMenuItem_Click(object sender, EventArgs e)
int i,j,k;
for(i=1;i&5;i++) /* 以下为三重循环 */  
for(j=1;j&5;j++)    
for (k=1;k&5;k++)    
if (i != k && i != j && j != k)    /*确保i、j、k三位互不相同*/
textBox1.Text = textBox1.Text + i.ToString() + j.ToString() + k.ToString() + "\r\n";   
void Draw1(string str1, int xPos = 0, int yPos = 0)
SolidBrush aBrush = new SolidBrush(Color.Blue);
Font aFont = new Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Millimeter);
Graphics graphic = this.CreateGraphics();
graphic.DrawString(str1, aFont, aBrush, xPos, yPos);
void ClsFrm()
Graphics graphic = this.CreateGraphics();
graphic.Clear(this.BackColor);
textBox1.Text = "";
textBox1.Visible =
private void 用号输出字母CToolStripMenuItem_Click(object sender, EventArgs e)
Draw1(" ****",100,100);
Draw1(" *",100,135);
Draw1(" *",100,170);
Draw1(" ****",100,205);
private void 输出特殊图案ToolStripMenuItem_Click(object sender, EventArgs e)
char a=(char)176;
char b=(char)219;
Draw1(b.ToString()+a.ToString()+a.ToString()+a.ToString()+b.ToString(),100,100);
Draw1(a.ToString()+b.ToString()+a.ToString()+b.ToString()+a.ToString(),100,135);
Draw1(a.ToString()+a.ToString()+b.ToString()+a.ToString()+a.ToString(),100,170);
Draw1(a.ToString()+b.ToString()+a.ToString()+b.ToString()+a.ToString(),100,205);
Draw1(b.ToString()+a.ToString()+a.ToString()+a.ToString()+b.ToString(),100,240);
a = (char)171;
b = (char)172;
Draw1(b.ToString() + a.ToString() + a.ToString() + a.ToString() + b.ToString(), 300, 100);
Draw1(a.ToString() + b.ToString() + a.ToString() + b.ToString() + a.ToString(), 300, 135);
Draw1(a.ToString() + a.ToString() + b.ToString() + a.ToString() + a.ToString(), 300, 170);
Draw1(a.ToString() + b.ToString() + a.ToString() + b.ToString() + a.ToString(), 300, 205);
Draw1(b.ToString() + a.ToString() + a.ToString() + a.ToString() + b.ToString(), 300, 240);
程序员,就选兄弟连,全国21所校区,7大IT课程,总监级讲师授课,项目经理一对一辅导,兄弟连专注11年IT教育培训,0元入学,学不会免费重修,推荐名企就业,学员都说好!
九九乘法表,老东西了,呵呵;private void 九九乘法表ToolStripMenuItem_Click(object sender, EventArgs e)
this.Width = wid2;
this.Height = hei2;
this.CenterToScreen();
for (i = 1; i & 10; i++)
for (j = 1; j & 10; j++)
result = i *
//printf("%d*%d=%-3d", i, j, result);/*-3d表示左对齐,占3位*/
Draw2(i.ToString() + "*" + j.ToString() + "= " + result.ToString(),6, (j-1)*110, 50+(i-1)*35);
兄弟,看你这劲头,不错!
再发点,给你加精华。
VB的shell函数研究
该函数可以运行的文件格式有:exe, com, bat。
打开记事本
ret = Shell("notepad", 1)打开计算器,磁盘清理
ret = Shell("calc.exe", 1)
ret = Shell("cleanmgr.exe", 1)这些程序位于 %SystemRoot%\system32\,可以不用输入完整路径,会自己找到这些程序;打开媒体播发机就不行,必须输入完整路径:"C:\Program Files\Windows Media Player\wmplayer.exe"打开控制面板
ret = Shell("rundll32.exe shell32.dll,Control_RunDLL", 1)打开控制面板项:
打开系统属性-常规
ret = Shell("rundll32.exe shell32.dll,Control_RunDLL sysdm.cpl,,0", 1)
打开添加/删除程序项
ret = Shell("rundll32.exe shell32.dll,Control_RunDLL appwiz.cpl,,0", 1)
打开显示器/桌面项
ret = Shell("rundll32.exe shell32.dll,Control_RunDLL desk.cpl,,0", 1)具体可参阅“VB打开控制面板大全”文章;用shell运行命令行程序
打开命令窗口
Shell "cmd.exe /k ", 1
执行ping本机命令
Shell "cmd.exe /k ping 127.0.0.1", 1
/k 表示运行完后不关闭命令窗口打开某个MSC语法示例如下:
打开设备管理器
Shell "mmc.exe C:\windows\system32\devmgmt.msc", 1
打开 服务 MSC
Shell "mmc.exe C:\windows\system32\services.msc", 1以上代码都经过调试,可以运行,可以打开各种项目;程序主窗口如下:点击某个项就会打开对应内容;这是从程序中执行 ping 127.0.0.1 后的结果:
用C#自带的SQL Server,大概是叫Express版本,以前没用过这个玩意;摸索一阵;在“工具”菜单中选“连接到数据库”,当出现“添加连接”对话框,在服务器名框中,要输入"XXXXXXXXXXx\SQLEXPRESS"这样的内容,才能连接,我连的是本机,XXXXXXX是本地服务器或本机名,SQLEXPRESS应该是C#自带Sql Server的服务器名,新建数据连接;然后在数据连接上右击,在弹出菜单中选择“新建SQL Server 数据库”,就可创建数据库,然后可建表;新建一张User表,C#代码如下:&% language="C#"%&&% namespace="System.Data"%&&% namespace="System.Data.SqlClient"%&% namespace="System.Data.OleDb"%&html&&script language="C#" runat="server"&void page_load(object serder, EventArgs e){//SqlConnection sqlcon=new SqlConnection("Data Source=uid=pwd=;database=dldb");
SqlConnection sqlcon = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=uid=pwd=;Integrated Security=True"); sqlcon.Open();SqlDataAdapter sqld=new SqlDataAdapter("select * from User",sqlcon);DataSet ds = new DataSet();
sqld.Fill(ds,"aaa");dg.DataSource=ds.Tables["aaa"].DefaultVdg.DataBind();sqlcon.Close();sqlcon=labcontent.Text+="查找成功";}&/script&&body&&form id="Form1" runat=server&&asp:datagrid id=dg runat=server/&&br&&asp:label id=labcontent runat=server/&&br&&/form&&/body&&/html&运行,编译器说:在关键字"User"附近有语法错误;我以为是连接字符串的问题,反反复复查,修改,结果每次都说:在关键字"User"附近有语法错误;郁闷了;后来又建了几张表,无意中把表名换为另一张,然后就通过了,程序成功执行,难道SQL Server中不允许建立一张名叫User的表吗,还有好像登录的用户名是dbo, 可能这个用户名不能建一张叫User的表;C#中的数据连接:程序执行后显示出表的内容:
vb6 在选项卡控件上载入(绘制)控件数组问题 窗体上有一个选项卡控件,选项卡控件上有2个组合框,名如下代码:For I = 2 To 9
Load aaa(I)
aaa(I).Left = aaa(I - 1).Left + aaa(0).Width
aaa(I).TabIndex = aaa(I - 1).TabIndex + 1: aaa(I).TabStop = True
Debug.Print aaa(I).Left
aaa(I).Width = aaa(0).Width
aaa(I).Top = aaa(0).Top
aaa(I).Visible = True
Next I不能在选项卡控件上绘制出控件数组,起初没有加tab键顺序的属性设置,加了,还是不行;此段代码放在窗体的Load事件里不行;放在Initialize事件里也不行;在窗体上就可以载入显示控件数组;实在无法解决,偶吐血......;求解答;
在vb爱好者乐园找到解答:用了SetParent这个API,很好很强大;完整代码如下:Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As LongPrivate ret As Long For i = 2 To 9
Load aaa(i)
aaa(i).Left = aaa(i - 1).Left + aaa(0).Width
aaa(i).TabIndex = aaa(i - 1).TabIndex + 1: aaa(i).TabStop = True
Debug.Print aaa(i).Left
aaa(i).Width = aaa(0).Width
aaa(i).Top = aaa(0).Top
aaa(i).Visible = True
ret = SetParent(aaa(i).hWnd, TabStrip1.hWnd)
Next i终于在 计算机猪 选项卡上绘制出了控件数组:
C# 索引器的示例,全部代码如下:using Susing System.Collections.GponentMusing System.Dusing System.Dusing System.Lusing System.Tusing System.Windows.F namespace index1{
public partial class Form1 : Form
public Form1()
InitializeComponent();
void Draw1(string str1, int xPos = 0, int yPos = 0)
SolidBrush aBrush = new SolidBrush(Color.Blue);
Font aFont = new Font("Arial", 8, FontStyle.Bold, GraphicsUnit.Millimeter);
Graphics graphic = this.CreateGraphics();
graphic.DrawString(str1, aFont, aBrush, xPos, yPos);
private void Form1_Paint(object sender, PaintEventArgs e)
SampleCollection&string& s = new SampleCollection&string&();
s[0] = "索引器的使用";
Draw1(s[0], 100, 100);
class SampleCollection&T&
private T[] arr = new T[100];
public T this[int i]
get { return arr[i]; }
set { arr[i] = }
} }如果把类SampleCollection,放到类Form1的前面,在设计时,当切换到设计视图的时候,就看不到Form1,并提示错误,“类Form1必须为命名空间中第一个类”,把类Form1放到前面,程序成功执行;
VB, 窗体上有一个选项卡控件,在每页选项卡上载入70个combobox, 7行10列,70个文本框控件,文本框控件 今天 13:39 提问者: 天下轻功第一 | 悬赏分:100 | 浏览次数:12次覆盖了combobox本身的文本框;切换到选项卡的不同页,显示另外一组70个combobox和文本框;combobox和文本框的父窗口都设为选项卡控件,这样这些控件才会位于选项卡控件之上;控件是控件数组,都是运行时动态载入的;现在文本框控件可以响应单击事件,但是combobox不响应单击和change事件,单击时click和change事件中的代码不会执行;代码挺乱,一时理不出头绪;请问都有哪些原因,combobox控件不会响应单击和change事件?应该不是设置选项卡为父窗口,combobox的风格,这些问题;帮我把程序调通给100分;
List&string&常用操作 参考:代码:using Susing System.Collections.GponentMusing System.Dusing System.Dusing System.Lusing System.Tusing System.Windows.F namespace list1{
public partial class Form1 : Form
IEnumerable&string& lstNew =
List&string& lstOne = new List&string&() { "January", "February", "March" };
List&string& lstTwo = new List&string&() { "January", "April", "March" };
List&string& lstThree = new List&string&() { "January", "April", "March", "May" };
List&string& lstFour = new List&string&() { "Jan", "Feb", "Jan", "April", "Feb" };
public Form1()
InitializeComponent();
void Draw1(string str1, int xPos = 0, int yPos = 0)
SolidBrush aBrush = new SolidBrush(Color.Blue);
Font aFont = new Font("Arial", 8, FontStyle.Bold, GraphicsUnit.Millimeter);
Graphics graphic = this.CreateGraphics();
graphic.DrawString(str1, aFont, aBrush, xPos, yPos);
private void Form1_Paint(object sender, PaintEventArgs e)
foreach (var s in lstOne)
Draw1(s,100,30+25*i);
i = i + 1;
foreach (var s in lstTwo)
Draw1(s, 400, 30 + 25 * i);
i = i + 1;
private void 交集ToolStripMenuItem_Click(object sender, EventArgs e)
lstNew = lstOne.Intersect(lstTwo, StringComparer.OrdinalIgnoreCase);
Draw1("交集:", 10, 130);
foreach (var s in lstNew)
Draw1(s, 100, 130 + 25 * i);
i = i + 1;
private void 差集ToolStripMenuItem_Click(object sender, EventArgs e)
lstNew = lstOne.Except(lstTwo, StringComparer.OrdinalIgnoreCase);
Draw1("差集:", 310, 130);
foreach (var s in lstNew)
Draw1(s, 400, 130 + 25 * i);
i = i + 1;
private void 转换成大写ToolStripMenuItem_Click(object sender, EventArgs e)
lstNew = lstOne.ConvertAll(x =& x.ToUpper());
Draw1("大写:",10, 230);
foreach (var s in lstNew)
Draw1(s, 100, 230 + 25 * i);
i = i + 1;
C# linq 演示程序using Susing System.Collections.GponentMusing System.Dusing System.Dusing System.Lusing System.Tusing System.Windows.F namespace linq1{
public partial class Form1 : Form
int[] scores = new int[] { 97, 92, 81, 60, 89, 45, 34, 78, 55,81,45,99};
public Form1()
InitializeComponent();
listBox1.Items.Add("原始数据序列");
listBox1.Items.Add("基本linq查询 &80");
listBox1.Items.Add("linq查询 &80并排序");
listBox1.Items.Add("linq查询 &80 排序 转换结果为string");
listBox1.Items.Add("linq查询 &80 结果集个数");
public void Draw1(string str1, int xPos = 0, int yPos = 0)
SolidBrush aBrush = new SolidBrush(Color.Blue);
Font aFont = new Font("Arial", 8, FontStyle.Bold, GraphicsUnit.Millimeter);
Graphics graphic = this.CreateGraphics();
graphic.DrawString(str1, aFont, aBrush, xPos, yPos);
public void FrmCls()
Graphics graphic = this.CreateGraphics();
graphic.Clear(Form1.DefaultBackColor);
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
switch(listBox1.SelectedIndex)
foreach (int i in scores)
Draw1(i.ToString(), 200 + 50 * k, 10);
k = k + 1;
IEnumerable&int& scoreQuery=
from score in scores
where score&80
//Execute the query.
foreach(int i in scoreQuery)
Draw1(i.ToString(), 200+k*50, 40);
k = k + 1;
IEnumerable&int& highScoresQuery =
from score in scores
where score & 80
orderby score descending
foreach(int i in highScoresQuery)
Draw1(i.ToString(), 200+k*50, 70);
k = k + 1;
IEnumerable&string& highScoresQuery2 =
from score in scores
where score & 80
orderby score descending
select String.Format("The score is {0}", score);
foreach(string str1 in highScoresQuery2)
Draw1(str1, 200, 10+k*30);
k = k + 1;
IEnumerable&int& highScoresQuery3 =
from score in scores
where score & 80
int cnt = highScoresQuery3.Count();
Draw1(cnt.ToString(), 300, 100);
一个sql脚本调试错误
从网上找的一个sql脚本,去除多余字符空格等等,编辑好;在sql server 2012 express 中新建一个项目,在sql 脚本 1中,把内容全部拷进去,全文如下: -- ---------------------------------------------------- Entity Designer DDL Script for SQL Server , and Azure-- ---------------------------------------------------- Date Created: 02/20/:54-- Generated from EDMX file: E:\Job\projects\WebTest\EF\Model1.edmx-- -------------------------------------------------- SET QUOTED_IDENTIFIER OFF;GOUSE [SchoolDB];GOIF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');GO -- ---------------------------------------------------- Dropping existing FOREIGN KEY constraints-- -------------------------------------------------- IF OBJECT_ID(N'[dbo].[FK_ClassStudent]', 'F') IS NOT NULL
ALTER TABLE [dbo].[T_Student] DROP CONSTRAINT [FK_ClassStudent];GOIF OBJECT_ID(N'[dbo].[FK_ClassTeacher]', 'F') IS NOT NULL
ALTER TABLE [dbo].[T_Teacher] DROP CONSTRAINT [FK_ClassTeacher];GO -- ---------------------------------------------------- Dropping existing tables-- --------------------------------------------------IF OBJECT_ID(N'[dbo].[T_Class]', 'U') IS NOT NULL
DROP TABLE [dbo].[T_Class];GOIF OBJECT_ID(N'[dbo].[T_Student]', 'U') IS NOT NULL
DROP TABLE [dbo].[T_Student];GOIF OBJECT_ID(N'[dbo].[T_Teacher]', 'U') IS NOT NULL
DROP TABLE [dbo].[T_Teacher];GO -- ---------------------------------------------------- Creating all tables-- -------------------------------------------------- -- Creating table 'T_Class'CREATE TABLE [dbo].[T_Class] (
[ID] int IDENTITY(1,1) NOT NULL,
[Name] nvarchar(max)
NOT NULL);GO - Creating table 'T_Student'CREATE TABLE [dbo].[T_Student] (
[ID] uniqueidentifier
[Name] nvarchar(max)
[ClassID] int
[Phone] nvarchar(max)
[Email] nvarchar(max)
NOT NULL);GO -- Creating table 'T_Teacher'CREATE TABLE [dbo].[T_Teacher] (
[ID] int IDENTITY(1,1) NOT NULL,
[Name] nvarchar(max)
[Address] nvarchar(max)
[Phone] nvarchar(max)
[Email] nvarchar(max)
[ClassID] int
NOT NULL);GO -- --------------------------------------------------- Creating all PRIMARY KEY constraints-- ---------------------------------------------------- --Creating primary key on [ID] in table 'T_Class'ALTER TABLE [dbo].[T_Class]ADD CONSTRAINT [PK_T_Class]
PRIMARY KEY CLUSTERED ([ID] ASC);GO -- Creating primary key on [ID] in table 'T_Student'ALTER TABLE [dbo].[T_Student]ADD CONSTRAINT [PK_T_Student]
PRIMARY KEY CLUSTERED ([ID] ASC);GO -- Creating primary key on [ID] in table 'T_Teacher'ALTER TABLE [dbo].[T_Teacher]ADD CONSTRAINT [PK_T_Teacher]
PRIMARY KEY CLUSTERED ([ID] ASC);GO -- ---------------------------------------------------- -- Creating all FOREIGN KEY constraints-- ---------------------------------------------------- Creating foreign key on [ClassID] in table 'T_Student'ALTER TABLE [dbo].[T_Student]ADD CONSTRAINT [FK_ClassStudent]
FOREIGN KEY ([ClassID])
REFERENCES [dbo].[T_Class]
ON DELETE NO ACTION ON UPDATE NO ACTION; -- Creating non-clustered index for FOREIGN KEY 'FK_ClassStudent'CREATE INDEX [IX_FK_ClassStudent]ON [dbo].[T_Student]
([ClassID]);GO -- Creating foreign key on [ClassID] in table 'T_Teacher'ALTER TABLE [dbo].[T_Teacher]ADD CONSTRAINT [FK_ClassTeacher]
FOREIGN KEY ([ClassID])
REFERENCES [dbo].[T_Class]
ON DELETE NO ACTION ON UPDATE NO ACTION; -- Creating non-clustered index for FOREIGN KEY 'FK_ClassTeacher'CREATE INDEX [IX_FK_ClassTeacher]ON [dbo].[T_Teacher]
([ClassID]);GO -- ---------------------------------------------------- Script has ended-- -------------------------------------------------- 然后执行,首先提示SchoolDB不存在,然后建立SchoolDB,再执行,Sqlserver提示,查询已执行,但是有错误,显示如下信息:消息 156,级别 15,状态 1,第 6 行关键字 'foreign' 附近有语法错误。表都已经创建;很明显红色下划线提示的地方错了;creating foreign key应当是create foreign key, 但是该行在第几十行了,为什么说第6行错误;
NDY的, 原来创建外键的语法是这样的,
creating这一句是注释, 正确的 如下:--create FOREIGN KEY on [ClassID] in table 'T_Student'ALTER TABLE [dbo].[T_Student]ADD CONSTRAINT [FK_ClassStudent]
FOREIGN KEY ([ClassID])
REFERENCES [dbo].[T_Class]
ON DELETE NO ACTION ON UPDATE NO ACTION;命令成功完成;
C# 伪造名字随机输出人名,伪造的,为什么要伪造呢,因为......有用,using Susing System.Collections.GponentMusing System.Dusing System.Dusing System.Lusing System.Tusing System.Windows.F namespace StringFac1{
public partial class Form1 : Form
string fn = "赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水";
string mn = "小晓泽少恩非正飞先宪笑正日";
string ln = "德东黑白红大小笑哭波浪芙蓉山峰东奇平";
public Form1()
InitializeComponent();
rd = new Random();
void Draw1(string str1, int xPos = 0, int yPos = 0)
SolidBrush aBrush = new SolidBrush(Color.Blue);
Font aFont = new Font("Arial", 4, FontStyle.Bold, GraphicsUnit.Millimeter);
Graphics graphic = this.CreateGraphics();
graphic.DrawString(str1, aFont, aBrush, xPos, yPos);
string BuildName1()
string fn1, mn1, ln1;
int fcnt = rd.Next(0, 37);
fn1 = fn[fcnt].ToString();
int twoORthree = rd.Next();
if (twoORthree % 2 == 0)
int mcnt=rd.Next(0,12);
mn1 = mn[mcnt].ToString();
int lcnt = rd.Next(0,17);
ln1 = ln[lcnt].ToString();
return fn1 + mn1 + ln1;
void ClsFrm()
Graphics graphic = this.CreateGraphics();
graphic.Clear(this.BackColor);
private void button1_Click(object sender, EventArgs e)
for (int i = 0; i & 20; i++)
string name1;
name1=BuildName1();
Draw1(name1, 100, 10 + i * 17);
}}R必须定义在Form1的范围内,如果放在BuildName1()函数内,则会输出20个相同的名字;
C# 自绘制 DataGridView控件,using Susing System.Collections.GponentMusing System.D using System.Dusing System.Drawing.Drawing2D;using System.Lusing System.Tusing System.Windows.Fusing System.Data.OleDb; namespace DataGridView2{
public partial class Form1 : Form
testDataGirdView dg1;
string connectionstring = "provider=microsoft.jet.oledb.4.0;data source=C:\\Program Files\\SolidWorks Corp\\SolidWorks\\data\\databases\\fit.mdb";
public Form1()
InitializeComponent();
dg1 = new testDataGirdView();
dg1.Left = 0;
dg1.Top = 0;
dg1.Width = this.W
dg1.Height=this.Height*80/100;
dg1.Parent =
OleDbConnection con = new OleDbConnection(connectionstring);
con.Open();
OleDbDataAdapter da = new OleDbDataAdapter(@"select * from ISO_Hole_Limits_Z_ZC", con);
DataSet ds = new DataSet();
da.Fill(ds);
dg1.DataSource = ds.Tables[0];
public class testDataGirdView : System.Windows.Forms.DataGridView
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
if (e.RowIndex == -1)
drawColumnAndRow(e);
e.Handled =
else if (e.ColumnIndex & 0 && e.RowIndex &= 0)
drawColumnAndRow(e);
e.Handled =
protected override void OnRowPrePaint(DataGridViewRowPrePaintEventArgs e)
base.OnRowPrePaint(e);
//是否是选中状态
if ((e.State & DataGridViewElementStates.Selected) ==DataGridViewElementStates.Selected)
// 计算选中区域Size
int width = this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible)+this.RowHeadersW
Rectangle rowBounds = new Rectangle(0 , e.RowBounds.Top, width,e.RowBounds.Height);
// 绘制选中背景色
using (LinearGradientBrush backbrush = new LinearGradientBrush(rowBounds, Color.GreenYellow, e.InheritedRowStyle.ForeColor, 90.0f))
e.Graphics.FillRectangle(backbrush, rowBounds);
e.PaintCellsContent(rowBounds);
e.Handled =
protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
base.OnRowPostPaint(e);
int width = this.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + this.RowHeadersW
Rectangle rowBounds = new Rectangle(0, e.RowBounds.Top, width, e.RowBounds.Height);
if (this.CurrentCellAddress.Y == e.RowIndex){
//设置选中边框
e.DrawFocus(rowBounds, true);
void drawColumnAndRow(DataGridViewCellPaintingEventArgs e)
// 绘制背景色
using (LinearGradientBrush backbrush =
new LinearGradientBrush(e.CellBounds,
ProfessionalColors.MenuItemPressedGradientBegin,
ProfessionalColors.MenuItemPressedGradientMiddle
, LinearGradientMode.Vertical)){
Rectangle border = e.CellB
border.Width -= 1;
//填充绘制效果
e.Graphics.FillRectangle(backbrush, border);
//绘制Column、Row的Text信息
e.PaintContent(e.CellBounds);
//绘制边框
ControlPaint.DrawBorder3D(e.Graphics, e.CellBounds, Border3DStyle.Etched);
} }自绘制之后好看多了;
自动填写和点击网银盾窗口
在以前的公司做一个程序,用程序来代替人工填写缴费,C#,在窗体上嵌入一个WebBrowser控件,用代码:打开X行网站,进入缴费页,填写所有缴费步骤;所有内容填完,跳出该行网银盾窗口;这个时候需要用代码填入用户名,口令,然后点击确定按钮;当时写了一个测试的程序,发现网上类似需求还不少,贴出来供大家参考,当时俺也是参考了网上资料;在文本框1输入内容,打开一个记事本,点击button1,将把文本框1的内容发送到记事本;打开windows计算器,点击button2, 将点中计算器的按钮“7”;X行网银盾窗口,标题为“XX银行网银盾”,有两个文本框,一个确定按钮;如果屏幕上有X行网银盾窗口,点击button3,输入用户名密码,自动点击确定;using Susing System.Collections.GponentMusing System.Dusing System.Dusing System.Lusing System.Tusing System.Windows.Fusing System.Runtime.InteropS namespace FindAndSend{
public partial class Form1 : Form
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
[DllImport("User32.dll")]
public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childe, string strclass, string FrmText);
public enum MSGEnum
WM_SETTEXT = 0x000C,
public Form1()
InitializeComponent();
private void button1_Click(object sender, EventArgs e)
IntPtr hwnd = FindWindow(null, "无标题 - 记事本");
IntPtr htxtwnd1 = FindWindowEx(hwnd, IntPtr.Zero, "EDIT", null);
SendMessage(htxtwnd1, 0x000C, IntPtr.Zero, textBox1.Text);
private void button2_Click(object sender, EventArgs e)
IntPtr hwnd = FindWindow(null, "计算器");
//IntPtr hbtn=FindWindowEx(hwnd,IntPtr.Zero,"BUTTON",null);
//SendMessage(hbtn,0x0201,IntPtr.Zero,null);
//SendMessage(hbtn,0x0202,IntPtr.Zero,null);
IntPtr BtnWnd = FindWindowEx(hwnd, IntPtr.Zero, null, "7");
SendMessage(BtnWnd, 0x0201, IntPtr.Zero,null);
SendMessage(BtnWnd, 0x0202, IntPtr.Zero,null);
private void button3_Click(object sender, EventArgs e)
FindAndSend();
public void FindAndSend()
IntPtr hwnd = FindWindow(null, "X行网银盾");
IntPtr htxtwnd1 = FindWindowEx(hwnd, IntPtr.Zero, "EDIT", null);
IntPtr htxtwnd2 = FindWindowEx(hwnd, htxtwnd1, "EDIT", null);
IntPtr hbtnwnd = FindWindowEx(hwnd, IntPtr.Zero, "BUTTON", null);
SendMessage(htxtwnd1, 0x000C, IntPtr.Zero, "用户名");
SendMessage(htxtwnd2, 0x000C, IntPtr.Zero, "密码");
SendMessage(hbtnwnd, 0x0201, IntPtr.Zero, null);
SendMessage(hbtnwnd, 0x0202, IntPtr.Zero, null);
}模拟鼠标点击要发送两个消息,down和up,其代码分别是0x2,这个点击鼠标是有窗口句柄的情况下,如果无句柄,要绝对激发一次鼠标单击,则用SendMessage不行,我后来在另一个程序中用到,网上找到一段代码,经测试可用;现一起贴出供大家参考;#region API
[DllImport("user32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);
enum MouseEventFlag : uint
Move = 0x0001,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
MiddleDown = 0x0020,
MiddleUp = 0x0040,
XDown = 0x0080,
XUp = 0x0100,
Wheel = 0x0800,
VirtualDesk = 0x4000,
Absolute = 0x8000
#endregion 。。。。。。
mouse_event(MouseEventFlag.LeftDown, 0, 0, 0, UIntPtr.Zero);
mouse_event(MouseEventFlag.LeftUp, 0, 0, 0, UIntPtr.Zero);。。。。。。其实我还不知道[Flag]表示啥子;可参考:使用Win32API需要引用:using System.Runtime.InteropS
一个C++文件拷贝程序,如下;#include &windows.h&#include &iostream.h& void main(){
char SourceFileName[MAX_PATH];
char DestFileName[MAX_PATH];
cout&&"请输入待拷贝的源文件名称\n";
cin&&SourceFileN
cout&&"请输入待拷贝的目标文件的名称\n";
cin&&DestFileN
Success=CopyFile(SourceFileName,DestFileName,TRUE);
if(!Success)
cout&&"拷贝失败,错误代码为:"&&GetLastError()&&
err=GetLastError();
switch(err)
cout&&"系统不能找到指定的路径!"&&
cout&&"系统不能找到指定的文件!"&&
cout&&"不能打开文件!"&&
cout&&"访问拒绝!"&&
cout&&"文件拷贝成功";
cin&&SourceFileN
} 以上代码还不是界面很友好, 先要输入 d:\文件.txt
再输入c:\文件.txt, 才能拷贝成功; 先输入d:\文件.txt
, 则会出现err=3的错误提示;
最近经理让弄个报表,用微软的Report Builder, 试了下, 这个东西还不错,如果用过水晶报表什么的,还是比较容易上手;不用写代码,熟悉了以后做报表还是比较快的,图表的功能丰富;可能需要写些SQL; 做报表的时候碰到个问题, 写出来跟大家分享; 在Report Builder中做饼图的时候, 假设如果是如下的数据:名称
43把饼图连接的数据集设置为该结果集, 就会自动计算各个数量占的百分比,自动画出饼图各个部分的比例;但是我现在需要显示飞行计划接受和未接受的比例,接受和未接受的数量是用两个select * 得到的;一开始我写了个存储过程,带2个输出参数,那么这两个输出参数其实是在一个行中的,运行存储过程后返回结果集如下:ret1
2000这样子就无法映射到饼图上,研究了很久似乎Report Builder不提供此功能;网上找些行转列的SQL,又写的挺乱,看的头晕;后来仔细看了下SQL教程(w3cschool的SQL教程,不错),原来UNION可以用来联合返回的结果集的,于是再写一个存储过程,大体如下:......Select count(*) as 数量, '接受' as 接受情况 from FlyTableWhere IsAccept=1UNIONSelect count(*) as 数量, '未接受' as 接受情况 from FlyTableWhere IsAccept=0GO......这样就得到了我所需要的结果集,示例如下:数量
接受情况1000
未接受把此结果集连接到饼图上, 结果就出来了;截个图,
作为一名T-SQL半熟手
我想我是一名T-SQL半熟手;今天写了一个存储过程,看似无错,Sql也不报错,但是只会执行else分支;写出来供大家参考,熟手想必不会犯此错误,鸟鸟们可以参考;...... datetime=null,
datetime=nullASBEGINif( ( is null) and ( is null) )......else......
这是正确的写法;
如果如下:if(@date1&&null and @date2&&null)......else......就只会执行else分支; 因为Sql要用is null, 或者
Sql Server 在存储过程中使用动态SQL以及动态Where条件的例子(以及在Report Builder中的显示)存储过程如下:USE [数据库名]GO/****** Object:
StoredProcedure [dbo].[XXXXXXXX]
Script Date:
15:48:23 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO ALTER PROCEDURE [dbo].[存储过程名] datetime=null,
datetime=null,@TmType int=1AS BEGIN if( ( is null) and ( is null) )begin Select 'XX总数' as 状态,COUNT(*) as 数量From tablename UNION Select '已发送' as 状态,COUNT(*) as 数量From tablenamewhere IsSent=1 UNION Select '已接收' as 状态,COUNT(*) as 数量From tablenamewhere IsReceive=1 UNION Select '已接受' as 状态,COUNT(*) as 数量From tablenamewhere IsAccept=1 end else begindeclare @RTType nchar(50)declare
nchar(500)declare
int if @TmType=1
set @RTType='ReceiveTime'if @TmType=2
set @RTType='TakeoffTimeNormalized'if @TmType=3
set @RTType='UpdateTime'if @TmType=4
set @RTType='SentTime' set @sqls='select @cnt1=COUNT(*) From tablename ' +'where (' +@RTType +'
and @date2)'exec sp_executesql @sqls,N' int output, datetime, datetime', output,@date1,
登录百度帐号推荐应用}

我要回帖

更多关于 小程序注释快捷键 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信