当前位置:网站首页>[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
边栏推荐
- 【最短路】Acwing1128信使:floyd最短路
- STM32F1与STM32CubeIDE编程实例-315M超再生无线遥控模块驱动
- 一度辍学的数学差生,获得今年菲尔兹奖
- 人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》
- QT | multiple windows share a prompt box class
- Talk about SOC startup (IX) adding a new board to uboot
- 聊聊SOC启动(七) uboot启动流程三
- Swiftui swift internal skill how to perform automatic trigonometric function calculation in swift
- The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
- 相机标定(2): 单目相机标定总结
猜你喜欢
禁锢自己的因素,原来有这么多
CMU15445 (Fall 2019) 之 Project#2 - Hash Table 详解
《通信软件开发与应用》课程结业报告
sql里,我想设置外键,为什么出现这个问题
聊聊SOC启动(六)uboot启动流程二
Flet教程之 17 Card卡片组件 基础入门(教程含源码)
Visual Studio 2019 (LocalDB)\MSSQLLocalDB SQL Server 2014 数据库版本为852无法打开,此服务器支持782版及更低版本
人大金仓受邀参加《航天七〇六“我与航天电脑有约”全国合作伙伴大会》
一起探索云服务之云数据库
Mastering the new functions of swiftui 4 weatherkit and swift charts
随机推荐
How to add aplayer music player in blog
Unsupervised learning of visual features by contracting cluster assignments
Talk about SOC startup (VII) uboot startup process III
聊聊SOC启动(十) 内核启动先导知识
In depth learning autumn recruitment interview questions collection (1)
Automated testing framework
.NET MAUI 性能提升
聊聊SOC启动(九) 为uboot 添加新的board
Flet教程之 18 Divider 分隔符组件 基础入门(教程含源码)
How to write test cases for test coupons?
Electron adding SQLite database
In SQL, I want to set foreign keys. Why is this problem
Easyui学习整理笔记
CMU15445 (Fall 2019) 之 Project#2 - Hash Table 详解
清华姚班程序员,网上征婚被骂?
HCIA复习整理
正在运行的Kubernetes集群想要调整Pod的网段地址
[filter tracking] comparison between EKF and UKF based on MATLAB extended Kalman filter [including Matlab source code 1933]
[filter tracking] strapdown inertial navigation simulation based on MATLAB [including Matlab source code 1935]
核舟记(一):当“男妈妈”走进现实,生物科技革命能解放女性吗?