当前位置:网站首页>[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
边栏推荐
- Two week selection of tdengine community issues | phase II
- [extraction des caractéristiques de texture] extraction des caractéristiques de texture de l'image LBP basée sur le mode binaire local de Matlab [y compris le code source de Matlab 1931]
- STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于SPI)
- Blog moved to Zhihu
- The road to success in R & D efficiency of 1000 person Internet companies
- Design intelligent weighing system based on Huawei cloud IOT (STM32)
- SwiftUI Swift 内功之如何在 Swift 中进行自动三角函数计算
- QT implements the delete method of the container
- Camera calibration (2): summary of monocular camera calibration
- R language uses image of magick package_ Mosaic functions and images_ The flatten function stacks multiple pictures together to form a stack layers on top of each other
猜你喜欢
Swiftui tutorial how to realize automatic scrolling function in 2 seconds
Talk about SOC startup (VI) uboot startup process II
18 basic introduction to divider separator component of fleet tutorial (tutorial includes source code)
Camera calibration (1): basic principles of monocular camera calibration and Zhang Zhengyou calibration
How to write test cases for test coupons?
[shortest circuit] acwing1128 Messenger: Floyd shortest circuit
Mastering the new functions of swiftui 4 weatherkit and swift charts
Flet教程之 14 ListTile 基础入门(教程含源码)
[data clustering] realize data clustering analysis based on multiverse optimization DBSCAN with matlab code
[filter tracking] strapdown inertial navigation pure inertial navigation solution matlab implementation
随机推荐
Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
Excel公式知多少?
Flet教程之 15 GridView 基础入门(教程含源码)
Half of the people don't know the difference between for and foreach???
SwiftUI 4 新功能之掌握 WeatherKit 和 Swift Charts
Internet Protocol
[Yugong series] go teaching course 005 variables in July 2022
The road to success in R & D efficiency of 1000 person Internet companies
SwiftUI 教程之如何在 2 秒内实现自动滚动功能
Android interview knowledge points
相机标定(2): 单目相机标定总结
Common SQL statement collation: MySQL
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?
【最短路】ACwing 1127. 香甜的黄油(堆优化的dijsktra或spfa)
Unsupervised learning of visual features by contracting cluster assignments
浙江大学周亚金:“又破又立”的顶尖安全学者,好奇心驱动的行动派
‘module‘ object is not callable错误
C#中在路径前加@的作用
博客搬家到知乎
【最短路】Acwing1128信使:floyd最短路