C#学习笔记(2)C#的基本语法

VB.NET 教程_01_基础语法     VB.Net教程简介: VB.Net是一种简单,现代,面向对象的计算机编程语言,由微软开发,将.NET Framework和公共语言运行库的强大功能与作为Visual Basic标志的生产力优势相结合。 Visual Basic .NET(VB.NET)是在.NET Framework上实现的面向对象的计算机编程语言。 虽然它是经典的Visual Basic语言的演变,但是它不... 阅读详情

C#基本语法

例:

using System;
namespace RectangleApplication
{
    class Rectangle
    {
        // 成员变量
        double length;
        double width;
        public void Acceptdetails()
        {
            length = 4.5;    
            width = 3.5;
        }
        public double GetArea()
        {
            return length * width;
        }
        public void Display()
        {
            Console.WriteLine("Length: {0}", length);
            Console.WriteLine("Width: {0}", width);
            Console.WriteLine("Area: {0}", GetArea());
        }
    }
   
    class ExecuteRectangle
    {
        static void Main(string[] args)
        {
            Rectangle r = new Rectangle();
            r.Acceptdetails();
            r.Display();
            Console.ReadLine();
        }
    }
}

代码逻辑:

  • 首先进入 Main 方法,创建一个名称为 r 的实例。
  • 然后调用 Acceptdetails 给 r 进行赋值。
  • 最后调用Display 方法打印结果。
  • 用于计算的 GetArea 方法在在调用 Display 时直接打印出来
  • using 关键字
    在任何 C# 程序中的第一条语句都是:
using System;

using 关键字用于在程序中包含命名空间。一个程序可以包含多个 using 语句。

  • class关键字
    class 关键字用于声明一个类。
  • 成员变量
    变量是类的属性或数据成员,用于存储数据。在上面的程序中,Rectangle 类有两个成员变量,名为 length 和 width。
  • 成员函数
    函数是一系列执行指定任务的语句。类的成员函数是在类内声明的。我们举例的类 Rectangle 包含了三个成员函数: AcceptDetails、GetArea 和 Display。
  • 实例化一个类
    在上面的程序中,类 ExecuteRectangle 是一个包含 Main() 方法和实例化 Rectangle 类的类。
    直白地解释就是:通过已有的类(class)创建出该类的一个对象(object),这一过程就叫做类的实例化。
    打个比方:你设计了一个飞机模型,交给工人师傅去加工制作,生产出一个(一批)飞机。飞机模型就相当于程序中的类,生产出来的飞机就是对象,生产飞机这一过程就叫做类的实例化。
    6.标识符
    标识符是用来识别类、变量、函数或任何其它用户定义的项目。在 C# 中,类的命名必须遵循如下基本规则:
  • 标识符必须以字母、下划线或 @ 开头,后面可以跟一系列的字母、数字( 0 - 9 )、下划线( _ )、@。
  • 标识符中的第一个字符不能是数字。
  • 标识符必须不包含任何嵌入的空格或符号,比如 ? - +! # % ^ & * ( ) [ ] { } . ; : " ’ / \。
  • 标识符不能是 C# 关键字。除非它们有一个 @ 前缀。 例如,@if 是有效的- - 标识符,但 if 不是,因为 if 是关键字。
  • 标识符必须区分大小写。大写字母和小写字母被认为是不同的字母。
    不能与C#的类库名称相同。
  • C# 关键字
  • 关键字不能用作标识符
  • 若想使用这些关键字作为标识符,可以在关键字前加上 @ 字符作为前缀。

在这里插入图片描述

C# 教程(菜鸟到中级) 第一章 简介 ##1.1 C# 有用的网站 C# Programming Guide - 介绍了有关关键的 C# 语言特征以及如何通过 .NET 框架访问 C# 的详细信息。 Visual Studio - 下载作为 C# 集成开发环境的 Visual Studio 的最新版本。 Go Mono - Mono 是一个允许开发人员简单地创建跨平台应用程序的软件平台。 C Sharp (programming language) - 维基百科解释 C#(编程语言)。 笔记 Console.Write("He 阅读详情

相关推荐

[零基础学C#] C#从小白到菜鸟 第2期 - 创建项目、程序结构、基本语法

★前言Hello,大家好!没错,又是我,上一期我们干了……额,好像啥也没干……那么,废话少说,让我们开始学习吧~●内容概要1.创建项目2.程序结构3.基本语法---------------------------------------------------------------------------------------------------------...

菜鸟小栈 3686

C# 基本语法

C# 是一种面向对象的编程语言。在面向对象的程序设计方法中,程序由各种相互交互的对象组成。相同种类的对象通常具有相同的类型,或者说,是在相同的 class 中。 例如,以 Rectangle(矩形)对象为例。它具有 length 和 width 属性。根据设计,它可能需要接受这些属性值、计算面积和显示细节。 让我们来看看一个 Rectangle(矩形)类的实现,并借此讨论 C# 的基本语法: using关键字用于在程序中包含System命名空间。 一个程序一般有多个usin...

chenggong9527的博客 458

C#入门1

基本语法: 1. using System 包含命名空间,一个空间可以包含多个语句 2.多行注释 /*shdjlkasjd*/ 单行注释 // 3.成员变量 length width 4.成员函数:Acceptdetails();GetArea();Display(); 5.包含main()方法和实例化rectangle 6.标识符 字母、下划线、@ 开头, 后面可以跟字母,下划线,数字,@ 不包含空格及嵌入式符号 不能是关键字,不能是类库名 必须区分大小写,C#大小写敏感...

xrj333的博客 550

C#语法基础——数据类型(1)

C#语法基础——数据类型,主要是用于初学者自学使用!!

UE5动画革命:如何用Motion Matching技术让你的游戏角色动作更流畅(附实战配置)

本文深入解析了UE5中Motion Matching技术的实战配置与应用。通过对比传统动画状态机的局限,详细阐述了如何构建动画数据库、在UE5中配置Pose Search Database及动画蓝图,并探讨了与IK融合、性能优化等进阶策略。该技术能显著提升游戏角色动作的流畅度与真实感,是下一代动画解决方案的核心。

weixin_29075633的博客 862

一:c#基本语法(2)(老田学习笔记)

数组:   代码   //二维数组        String[,] abcd = new string[2, 4];//建立一个2*4的数组        abcd[0, 0] = "田洪川";        // abcd[0,1] = "";        abcd[0, 2] = "自由职业者";        abcd[0, 3] = "26岁";        abcd[1...

weixin_33757609的博客 109

Vue2项目实战:海康威视WEB无插件开发包V3.4从下载到多画面预览(附完整代码)

本文详细介绍了在Vue2项目中集成海康威视WEB无插件开发包V3.4实现多画面监控预览的完整实战方案。内容涵盖从开发包下载、Nginx代理配置、核心组件封装到多画面并发加载与性能优化的全流程,并提供了完整的代码示例,帮助开发者高效解决浏览器无插件播放与多路视频流加载的难题。

c7d8e9的博客 320

C#:基本语法看这一篇就够了

本文来自w3c教程的C#教程的学习笔记,对其中的示例有所删减与变更,建议以以下链接为准。C# 简介_w3cschool。

weixin_43431593的博客 3957

rbf神经网络python预测代码_RBF神经网络预测

%用RBF网络来预测股票走势clcclear%归一化数据input=[0 0 0 0 0 0.0277;0.0177 0.0292 0.0184 0.0122 0.0264 0.0492;0.0374 0.0946 0.0393 ...

weixin_39951419的博客 1889

LPDDR5 物理层一致性测试(连载・下):电平、过冲下冲与 Rx 接收眼图 Mask 掩模完整指标解读

本文系统梳理LPDDR5物理层一致性测试全流程,涵盖差分/单端电平、边沿斜率、交叉点电压、过冲下冲及CS/CA/DQ接收眼图掩模(Rx Mask)测试,详解各参数定义与工程实操要点。强调配置需与DRAM MR寄存器同步,突出差分≠合格、面积积分不可忽视、掩模失败优先排查参考电压与信号完整性等高频坑点,为硬件调试与SI工程师提供权威参考。

一只豌豆象的博客 42

C#学习笔记1:C#基本文件结构与语法

现在开始我的C#学习之路,本文仅个人笔记使用,希望对大家有帮助

NULL指向我的博客 1976

华为面试手撕真题【求1-n的最小公倍数】

求1-n的最小公倍数

MISAYAONE的博客 2万+

C#:基本语法总结

PS:最近学了C#,很多地方和原理和C以及C++是类似的,因此基本语法我只总结了一些相对于不同的定义方式以及一些新的概念。 这里也不再介绍相关编译环境和工程的建立了。 一、Hello World 和其他语言一样,都是从Hello World着手的。 代码: Console.Write("Hello World!");//不会换行 Console.WriteLine("Hello Wor...

信仰.的博客 4630

android 如何分析应用的内存(十六)——使用AS查看Android堆

在前面,先介绍了如何使用jdb和VS code查看应用栈相关内容。本文将介绍,如何查看堆中的内容。

安仔的博客 4254

帆软报表导出各种格式之后台导出

我们前面介绍了帆软报表在界面上的导出是通过类似的URL:http://localhost:8075/webroot/decision/view/report?op=export&sessionID=10653244-3e46-408c-bc54-f89a214a9bc7&format=image&extype=PNG 来完成的,就是带OP=export以及format参数来完成的。如果不从界面传参数,比如我们自己实现了一个HTTP接口,也可以通过传参数format来完成各种格式的导

帆软爱好者的专栏 4270

C#基础知识 - 基本语法篇

② 使用别名可以提高代码的可读性和可维护性,特别是在涉及到长、复杂的类型或命名空间时。C# 中的关键字是编译器预先定义好的一些单词,也可以称为保留字或者保留标识符,这些关键字对编译器有特殊的意义,不能用作标识符。在一些特殊情况下,可以使用typedef命令来创建类型别名,这种方式只适用于在BCL(基础类库)中定义的类型。① 别名仅在定义它们的范围内有效,如果使用别名的代码超出了别名的作用域,就需要重新引用完整的类型或命名空间。此类由标准类库提供。指令,可以非限定的方式使用作为相应命名空间成员的类型。

emmmheng的博客 1790

Java Swing教程-16. Swing中的图形绘制

这篇教程介绍了Java Swing中的图形绘制功能,主要内容包括: Graphics类的基本使用 - 介绍了如何重写paintComponent方法实现自定义绘制,以及基本图形绘制方法(线条、矩形、椭圆、多边形等) 文本与图片绘制 - 讲解了文本绘制方法、字体设置和图片加载绘制技术 颜色与字体设置 - 包括预定义颜色、RGB自定义颜色、透明色设置以及字体样式控制 案例实现 - 提供了一个简单绘图程序的框架,支持鼠标绘制不同图形、选择工具和自定义颜色等功能 教程通过代码示例详细演示了各种绘图操作,适合Java

无 233

C#基本语法

文章目录输出为了避免闪退现象system命名空间控制台输出console.write(),console.writeline()使用索引输出,索引号必须从0开始不间断顺延只能输出object数组,其他数组不可以输出数组元素的指定位置控制台输入ReadKey()方法Read()方法ReadLine()方法.NET Framework基本语法解决方案文件和项目文件以及类文件之间的关系常量与变量引用类型与值类型常量与变量值类型与引用类型的区别数据类型object类型dynamic类型装箱和拆箱数据类型之间的转换使

weixin_43725617的博客 2563

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

006-C# 基本语法

C# 是一种强类型、面向对象的编程语言,其语法设计简洁、易用,同时功能强大。以下是 C# 的基本语法,包括变量、数据类型、运算符、控制流、循环、数组和方法等。通过学习变量、运算符、控制流、循环、数组和方法等核心部分,你已经掌握了编写 C# 程序的基本能力。下面我们继续扩展 C# 的基本语法,涵盖更多高级功能,如类与对象、属性与字段、接口、委托与事件、泛型等内容。通过以上内容,掌握了 C# 的基本和高级语法后,可以编写更加复杂和实用的程序。类是数据和方法的集合,用于描述对象的特性和行为。

小宝哥Code的专栏 1063

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

C# 程序结构||C# 基本语法

本节我们将学习 C# 编程语言的结构,为了让大家能够对 C# 程序结构有个更好的理解,我们会先演示一个最小的、最简单的 C# 程序结构,以便作为接下来的章节的参考。

爱编程的鱼的博客 986

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

C#:基本语法

本人在实习过程需要用C#进行开发,但本人之前的技术栈是C++方向,所以在菜鸟教程上速通了一下C#的基本语法,总的来说和C++还是非常相似的。

wy2458984254的博客 2908

C# 入门—基本语法

C# 入门—基本语法

白白白鲤鱼的博客 2863
上一篇: C#学习笔记(1)简介
下一篇: 我在CodeGym上学Java(二)Java简介:屏幕输出、String和int类型
Akzeptieren
博客等级 码龄8年 65粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值