第二节:Web前端-ASP.NET之C#基础

第二节:Web前端-ASP.NET之C#基础

第二节:Web前端-ASP.NETC#基础

学习ASP.NET,要掌握学习语言,控件等技能,

<div style="text-align: center; line-height: 30px;">
 <input name="TextBox1" type="text" value="水电费" id="TextBox1"/>
 </input type="submit" name="Button1" value="Button" id="Button1"/><br/>
 <span id="Label1">达</span>
</div>

c#编程指令操作对象:

基本概念:
关键字:

class const continue double decimal
default delegate else enum event
explicit extern false finally gixed
float for foreach goto if
lock long namespace new null
object operator out override params
private protected public readonly ref
return sbyte Sealed short sizeof
stackalloc static string struct switch
this throw true try typeof
uint ulong unchecked unsafe ushort 
using virtual void volatile while
abstract as base bool break
byte case catch char checked

ascii码表:

代码 字符
32 空格
33 !
34 "
35 #
36 $
37 %
38 &
39 '
40 (
41 )
... ...

数据类型:

字符串型:string
整型: int

语法规则

protected void Button_Click(object sender, EventArgs e) {
 int a,b,c;
 double C;
 // 赋值
 a = 1;
 b = 2;
 c = 3;
 c = a + b + c;
 C = a + b + c;
 
 Respense.Write(C);
}

protected void Button_Click(object sender, EventArgs e){
 int age = 12;
 double weight, height;
 weight = 12.1;
 height = 13.1;
 WriteContent(age, weight, height);
}

数组类型

数据类型分 引用类型和值类型

值类型:分
枚举类型,结构类型,简单类型

简单类型:
整数类型,实数类型,字符类型,布尔类型

字符串类型的变量:string
整型int 32
短整型short 16
双精度double d
单精度float f
布尔型boolean
日期时间dateTime

protected void Button_Click(object sender, 
EventArgs e) {
 string a = "12";
 string b = "123";
 Response.Write(a+b);
 Response.Write("<br/>"); // 换行
 int i_a;
 int i_b;
 i_a = Convert.ToInt16(a);
 i_b = Convert.ToInt16(b);
 Response.Write((i_a+i_b).ToString());
 Response.Write("<br/>"); // 换行

 char char_a;
 char_a = Convert.ToChar(65);
 Respense.Write(char_a);
}

数组

// 数组的定义与应用
protected void Button_Click(object sender, EventArg e) {
 // 数组的定义
 int[] a;
 // 声明一个int型的一维数组
 a = new int[5];
 // 或者 int[] a = new int[5];
 a[1] = 1; a[2] = 2;
 Response.Write(a[1].ToString());
 Response.Write(a[2].ToString());
 int[] b = new int[] {1,2,3,4};
}
double  a;
a = new double[4] { 23.23, 12.12, 12.34 };
string[] str_a = new String[4];
str_a[0] = a[0].ToString();
str_a[1] = a[1].ToString();
str_a[2] = a[2].ToString();
Response.Write(str_a[0]);
Response.Write(str_a[1]);
Response.Write(str_a[2]);

数组类型转换:

数据类型的默认值
字符串型数组的默认值为:null
而不是""

运算符和表达式

表达式分类:
赋值表达式,运算表达式,方法表达式。

运算符:

算数运算符>逻辑运算符>关系运算符>赋值运算符

运算符

x = a++ +b +c;
// x = a+b+c; a = a+1;
x = ++a +b +c;
// a=a+1; x=a+b+c;

关系运算符

>, <, >=, <=, ==, !=, &&, ||

程序流程分类:

if语句和switch语句:

break;
continue;
return;

循环:
while,do-while,for

if选择语句:

通过条件表达式-》执行语句
通过条件表达式-》执行语句1或执行语句2

if(条件表达式){
 表达式成立,执行语句;
 }else {
 表达式成立,执行语句;
}
<asp:Button ID=“btn_submit” runat = "server" Text="Button" onclick="btn_submit_Click" />

水仙花数

一个三位数其各位数字的立方和等于该数本身

public class Demo {
  public static void main(String[] args) {
    int count = 0;    //定义水仙花数的个数
    for(int i=100;i<=10000;i++){ 
      int b = i/100;    //取得百位数
      int s = (i-100*b)/10;    //取得十位数
      int g = (i-s*10-b*100);    //取得个位数
       
      if(i==g*g*g+s*s*s+b*b*b){ //水仙花数判定
        System.out.print(i+" ");  //输出符合条件的数
        count++;
      }
    }
    System.out.println("总共有"+count+"个");  
  }
}

水仙花数指一个N位正整数(N>=3),它的每个位上的数字的N次幂之和等于它本身。

三个数从小到大排序

    if(a>b)    /*如果a大于b,借助中间变量t实现a与b值的互换*/
    {
        t = a;
        a = b;
        b = t;
    }
    if(a>c)    /*如果a大于c,借助中间变景t实现a与c值的互换*/
    {
        t = a;
        a = c;
        c = t;
    }
    if(b>c)    /*如果b大于c,借助中间变量t实现b与c值的互换*/
    {
        t = b;
        b = c;
        c = t;
    }

猴子吃桃问题

定义 day、x1、x2 为基本整型
10 天早上,只剩下一个桃子

    int day,x1,x2; 
    day=9;
    x2=1;
    while(day>0)
    {
        x1=(x2+1)*2;    /*第一天的桃子数是第二天桃子数加1后的2倍*/
        x2=x1;
        day--;    /*因为从后向前推所以天数递减*/
    }

while循环可以0次循环,do-while循环至少会被执行一次循环。

for(计算表达式1;条件表达式;计算表达式2){
 // 执行语句
}

continue:跳出当前循环,执行下一次循环

冒泡排序法

10 个数按照从小到大的顺序进行排序

从左到右开始,第一个和第二个进行比较,大的那个就被挑出来,与第三个进行比较,接下来就是依次按照这个方法比较

for(int num=1;num<arr.length;num++){  
  
 for(int index=0;index<arr.length-num;index++){  
  
   if(arr[index]>arr[index+1]){  
     int temp = arr[index];  
     arr[index] = arr[index+1];  
     arr[index+1] = temp;  
   }  
 }  
}  

结言

好了,欢迎在留言区留言,与大家分享你的经验和心得。

感谢你学习今天的内容,如果你觉得这篇文章对你有帮助的话,也欢迎把它分享给更多的朋友,感谢。

作者简介

达叔,理工男,简书作者&全栈工程师,感性理性兼备的写作者,个人独立开发者,我相信你也可以!阅读他的文章,会上瘾!,帮你成为更好的自己。长按下方二维码可关注,欢迎分享,置顶尤佳。

努力努力再努力Jeskson

原文地址:https://www.cnblogs.com/dashucoding/p/10474084.html