当前位置:网站首页>[full stack plan - programming language C] basic introductory knowledge
[full stack plan - programming language C] basic introductory knowledge
2022-07-07 11:52:00 【Poplar branch】
List of articles
Preface
Write a project oriented article for the first time , Whether it's Unity Game article , It is still used for services Unity Developed C# In the article , Will not be very patient to ponder the details .
I don't want to pay attention to details , Just write something that can run , Digging deep is easy to consume your enthusiasm , And the articles written are also very verbose and cumbersome .
Get positive feedback when running , Don't keep groping for some details without a sense of achievement , This kind of self-confidence is easy to hit , Stride forward , You can do it without understanding , Then optimize , Constantly deal with details that have not been handled well 、bug, Iterative forward .
Hope everyone can enjoy the solution Bug The process of
Understanding of editor
purple logo Our software is called Microsoft Visual Studio
.
Blue logo Our software is called Visual Studio Code
.
Both software are Microsoft's stuff , They are all software loved by developers , It's just that their fields are different .
The differences between the two are roughly as follows , Just pass it by as common sense .
① violet logo The compiler , Blue logo Editor
VisualStudio( abbreviation VS) It's Microsoft's development kit series products , It's a basically complete set of development tools , It includes most of the tools needed throughout the software lifecycle , Such as UML Tools 、 Code control tools 、 Integrated development environment (IDE) etc. . Generally speaking , Is a ` compiler .
visual studio code Microsoft Corporation is a project : To run on Mac OS X、Windows and Linux Above , For writing modern Web And cross platform source code editor for Cloud Applications . informally , Is a Editor
② Cross platform operation capabilities are different .
Visual Studio Various functions can only be used in Windows and macOS(Mac OS X ) Run on , You cannot edit by skipping platforms .
visual studio code Is a true cross platform editor , It can be used on the platform that users are accustomed to , Instead of having to migrate to Windows On .
③ Function differently
Visual Studio It's the most popular at the moment Windows Integrated development environment for platform applications . Advanced development tools are provided 、 Debugging function 、 Database function and innovation function , Help quickly create the most advanced applications on various platforms , Developing new programs .
visual studio code It integrates all the features that a modern editor should have , Including syntax highlighting , Customizable hotkey binding , Bracket matching and code fragment collection , This editor also has the right Git Out of the box support .
How to use it? C# Create project . And the hierarchical relationship of the whole project directory .
The process of creating a new project
① Create a new project on the homepage
② The type selection is console application
③ Configuration items
This is mainly to determine the name ( The name of the project and the name of the solution ) and Storage location of the project .
What I want to introduce here is project
and Solution
The relationship between . Projects are subsets of solutions , in other words , Multiple projects can be created under one solution , In a project , There is a main class with a main function and others that can declare several additional classes .
Specific hierarchical relationship diagram
④ Finally, pay attention to the menu bar and toolbar
Go over the basics
One 、 Input and output
Want to run Hello World
, Want to test A+B
Result , Then it is inseparable from the use of the most basic output and input .
stay C# in , Want to input and output , Cannot leave use Console Class helps us meet our needs .
C# Console Class is mainly used for input and output operations of console applications
The following four methods are commonly used for input and output
The format of the input statement is Console.ReadLine(); Pay attention to ,C# Input statement , The default input is string , If you want to input integer data, you need to convert .
Now I'll show you how to define a string to receive the input string information : string str = Console.ReadLine();
If you want to input integer or floating-point data ,C# There are two ways of data conversion .
① Convert function
int num;
num = Convert.ToInt32(Console.ReadLine());
because Console.ReadLine() Only accept data in string format .
function Convert.ToInt32() Convert the data entered by the user into int data type
② Parse function
C# Parse Method is used to convert a string type to any type , The specific grammatical form is as follows .
data type Variable name = data type .Parse( Value of string type );
Two 、C# data type
stay C# in , Variables are divided into the following types :
Value type (Value types)
Reference type (Reference types)
Pointer types (Pointer types)
① Value type
Value type variables can be assigned directly to a value . They are from class System.ValueType Derived from .
Value typeContains data directly
.
② Reference type
The reference type does not contain the actual data stored in the variable , But they contain references to variables .
let me put it another way , They refer to aMemory location
.
③ Pointer types
Pointer type variables store another type of memory address .C# Pointer in and C or C++ Pointers in have the same function .
Put it all together , It's this mind map
If you want to get the exact size of a type or variable on a specific platform , have access to sizeof Operator
. expression sizeof(type) Generates a storage size that stores objects or types in bytes
3、 ... and 、 Operator
Every language is similar , Just check and explain repeatedly , If you are not clear, you can check the document at any time to sweep away omissions
C# Operator
Four 、 Judgment statement 、 Loop statement
Judgment statements and loop statements are also similar to each statement
5、 ... and 、 Cognition of complex data types
① Constant
stay C# in , Can't use C and C++ In the usual way to make use #define Preprocessor instructions define constants .
Constants are used const Keywords to define ,const What is defined is static const .
static const Remember two points here :
① Load as class loads , namely , A class generation , It also generates .
② Can be called directly using classes . Its value is universal in the whole world . namely , I'm working on functions 1 It was modified in , So I'm in the function 4 When using this static constant in , It's not zero , Not other values , That's the function. 1 Modified results in .
② Enumeration type
Use enum To define enumeration types . In enumeration type , It can be understood as using from 0 The integer of the starting count refers to the data placed in it , such as 0 representative Spring 了 ,1 representative Summer 了 .
//1、 Default writing
enum Season
{
Spring,
Summer,
Autumn,
Winter
}
//2、 Custom type
enum ErrorCode : ushort
{
None = 0,
Unknown = 1,
ConnectionLost = 100,
OutlierReading = 200
}
// Enumeration type , It's from 0 At the beginning , that Season This enumeration has only 0,1,2,3
var c = (Season)3;
Console.WriteLine(c);// Output results :Winter
// Test another number 4
var d = (Season)4;
Console.WriteLine(d);// Output results :4
③ Structure type
Use struct Keyword defines the structure type , Methods can be written in the structure
public struct Coords
{
// Methods can be written in the structure
public Coords(double x,double y)
{
X = x;
Y = y;
}
// Here is also the method , And it shows that there are references
public double X {
get; }
public double Y {
get; }
//C# in $ The function of symbols is C#6.0 A new feature in , That is, string splicing optimization .
// ToString () Is to convert a non string value into a string
//=> yes Lambad expression :https://docs.microsoft.com/zh-cn/dotnet/csharp/language-reference/operators/lambda-operator#code-try-0
// Toss it when writing an article
public override string ToString() => $"{X},{Y}";
}
6、 ... and 、 Array
Declaration of arrays , and c and c++ Different .C and c++ It says double g[N][N]
java and C# It should be written
double[] array1 = new double[5];
about C# for , Two dimensional arrays do need attention
Two dimensional arrays are different from conventional arrays
Declaration of two-dimensional array : Type of element [ , ] Name of array =new Type of element [ Row number , Number of columns ];
int[,] arr = new int[4, 3]
One dimensional array ,Length Attribute represents the number of elements in the array , And in a two-dimensional array Length It means line * Column Result
a、 Use foreach It can be traversed simply and quickly .
b、 Array of GetLength() You can get the length of the specified latitude . Its method is passed into 0 You can get the number of lines . Pass in 1 You can get the number of columns
int[,] arr = new int[,] {
{
1, 2 }, {
3, 4 }, {
5, 6 }, {
7, 8 } };
for (int i = 0; i < arr.GetLength(0); i++)
{
for (int j = 0; j < arr.GetLength(1); j++)
{
Console.WriteLine (arr[i, j]);
}
}
summary
C# In the basic knowledge of , It's good to know what I listed above .
Most are similar to other languages , The sentence is if、while、for wait ;
Data types are int、double、long etc. .
I think the only thing worth noting isconst The declared default is static constant
andDeclaration of two-dimensional array
The next one is to write a small one directly using basic knowledge Demo, Then proceed directly into C# Advanced features of
边栏推荐
- 通过环境变量将 Pod 信息呈现给容器
- 《论文阅读》Neural Approaches to Conversational AI(1)
- [question] Compilation Principle
- Internet Protocol
- 'module 'object is not callable error
- Unsupervised learning of visual features by contracting cluster assignments
- 【全栈计划 —— 编程语言之C#】基础入门知识一文懂
- Design intelligent weighing system based on Huawei cloud IOT (STM32)
- 清华姚班程序员,网上征婚被骂?
- 《通信软件开发与应用》课程结业报告
猜你喜欢
Excel公式知多少?
聊聊SOC启动(六)uboot启动流程二
【滤波跟踪】基于matlab扩展卡尔曼滤波EKF和无迹卡尔曼滤波UKF比较【含Matlab源码 1933期】
人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》
一起探索云服务之云数据库
【紋理特征提取】基於matlab局部二值模式LBP圖像紋理特征提取【含Matlab源碼 1931期】
正在運行的Kubernetes集群想要調整Pod的網段地址
What is cloud computing?
5V串口接3.3V单片机串口怎么搞?
[filter tracking] strapdown inertial navigation pure inertial navigation solution matlab implementation
随机推荐
Internet Protocol
VIM command mode and input mode switching
Rationaldmis2022 array workpiece measurement
超标量处理器设计 姚永斌 第10章 指令提交 摘录
There are so many factors that imprison you
C#中在路径前加@的作用
Software design - "high cohesion and low coupling"
5V串口接3.3V单片机串口怎么搞?
【滤波跟踪】基于matlab捷联惯导仿真【含Matlab源码 1935期】
Have you ever met flick Oracle CDC, read a table without update operation, and read it repeatedly every ten seconds
R語言使用magick包的image_mosaic函數和image_flatten函數把多張圖片堆疊在一起形成堆疊組合圖像(Stack layers on top of each other)
STM32 entry development write DS18B20 temperature sensor driver (read ambient temperature, support cascade)
【数据聚类】基于多元宇宙优化DBSCAN实现数据聚类分析附matlab代码
正在運行的Kubernetes集群想要調整Pod的網段地址
'module 'object is not callable error
Design intelligent weighing system based on Huawei cloud IOT (STM32)
R language Visual facet chart, hypothesis test, multivariable grouping t-test, visual multivariable grouping faceting boxplot, and add significance levels and jitter points
Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
R language uses the quantile function to calculate the quantile of the score value (20%, 40%, 60%, 80%), uses the logical operator to encode the corresponding quantile interval (quantile) into the cla
【滤波跟踪】基于matlab扩展卡尔曼滤波EKF和无迹卡尔曼滤波UKF比较【含Matlab源码 1933期】