当前位置:网站首页>C # basic knowledge (1)
C # basic knowledge (1)
2022-07-03 23:06:00 【BeanInJ】
List of articles
Write it at the front
C# ( The English name is CSharp) ..NET It's a development platform , and C# It's a kind of .NET The programming language used on the development platform
1、 first C# Program
namespace test
{
class Program
{
static void Main(string[] args)
{
// This is the note
Console.Write(" first C# Program , ");
Console.WriteLine(" This is the first console program ");
}
}
}
- The first 11 Go to the first place 13 Line is Main Method , There can only be one in each class
- Console.Write(); // Print , Console.WriteLine(); // Line to print
2、 Basic data type
Integer types
class type | Value range |
---|---|
sbyte | Signed number , Occupy 1 Bytes ,-27〜27-1 |
byte | An unsigned number , Occupy 1 Bytes ,0〜28-1 |
short | Signed number , Occupy 2 Bytes ,-215〜215-1 |
ushort | An unsigned number , Occupy 2 Bytes ,0〜216-1 |
int | Signed number , Occupy 4 Bytes ,-231〜231-1 |
uint | An unsigned number , Occupy 4 Bytes ,0〜232-1 |
long | Signed number , Occupy 8 Bytes ,-263〜263-1 |
ulong | An unsigned number , Occupy 8 Bytes ,0〜264-1 |
floating-point
class type | Value range |
---|---|
float | Single precision floating point , Occupy 4 Bytes , Keep at most 7 Decimal place |
double | Double precision floating point , Occupy 8 Bytes , Keep at most 16 Decimal place |
Other types
class type | explain |
---|---|
char | Character , for example ‘a’、‘ in ’ etc. |
String | String type , for example “abc”、“123” etc. (String Not a basic data type ) |
bool | Boolean , Only true and false Two values |
4、 Various symbols
4.1、 Escape character
Escape character | explain |
---|---|
\’ | Single quotation marks |
\" | Double quotes |
\ | The backslash |
\0 | empty |
\a | Warning ( Produce a beep ) |
\b | Backspace |
\f | Change the page |
\n | Line break |
\r | enter |
\t | Horizontal tabs |
\v | Vertical tabs |
4.2、 Arithmetic operator
Operator | say bright |
---|---|
+ | Add |
- | Subtraction |
* | Multiplication |
/ | division |
% | Remainder |
example :
class Program
{
static void Main(string[] args)
{
Console.WriteLine(" Thousand bit " +1234 / 1000);
Console.WriteLine(" Hundred bit " + 1234 / 100 % 10);
Console.WriteLine(" ten " + 1234 / 10 % 10);
Console.WriteLine(" bits " + 1234 % 10);
Console.WriteLine(" Connection string :" + "123" + "456");
}
}
4.3、 Logical operators
Logical operators | explain |
---|---|
&& | Logic and , If both sides of the operator are True, Then the whole expression is True, Otherwise False; If the left operand is False, The expression on the right is not evaluated , amount to “ And ” The meaning of |
|| | Logic or , If one or both sides of the operator are True, The whole expression is True, Otherwise False; If left is True, The expression on the right is not evaluated , amount to “ or ” The meaning of |
! | Logic is not , Represents logic contrary to the original logic |
4.4、 Comparison operator
Operator | say bright |
---|---|
== | Equal to the judge |
!= | Don't wait to judge |
> | Indicates that the value of the left expression is greater than the value of the right expression |
< | Indicates that the value of the left expression is less than the value of the right expression |
>= | Indicates that the value of the expression on the left is greater than or equal to the value of the expression on the right |
<= | Indicates that the value of the expression on the left is less than or equal to the value of the expression on the right |
4.5、 An operator
Operator | explain |
---|---|
& | Bitwise AND . Both operands are 1, Then the whole expression is 1, Otherwise 0; You can also compare Boolean values , amount to “ And ” operation , But not short circuiting |
| | Press bit or . Both operands are 0, Then the whole expression is 0, Otherwise 1; You can also compare Boolean values , amount to “ or ” operation , But not short circuiting |
~ | Bitwise non . When the calculated value is 1 when , The result of operation is 0; When the calculated value is 0 when , The result of operation is 1. This operator cannot be used for Boolean . Negate a positive integer , Add... To the original number 1, Then take a negative number ; Negate negative integers , Add... To the original number 1, Then take the absolute value |
^ | Bitwise XOR . Only two different results of the operation are 1, Otherwise 0 |
<< | Move left . Move the operand on the left of the operator to the left by the specified number of digits on the right of the operator , The part on the right that is vacated due to movement repair 0 |
>> | Move the sign right . Move the operand on the left of the operator to the right by the specified number of digits on the right of the operator . If it's a positive value , The part left vacant due to movement is filled 0; If it's negative , The part left vacant due to movement is filled 1 |
>>> | unsigned right shift . and >> They move in the same way , Just no matter positive or negative , All the parts vacated due to movement are filled 0 |
4.6、 Ternary operator
Boolean expression ? expression 1: expression 2
class Program
{
static void Main(string[] args)
{
Console.WriteLine("10 by :"+(10 % 2 == 0 ? " even numbers ":" Odd number "));
}
}
4.7、 Assignment operator
Symbol | explain |
---|---|
= | x=y, The value to the right of the equal sign is given to the variable to the left of the equal sign , That is, the variable y The value of is assigned to the variable x |
+= | x+=y, Equate to x=x+y |
-= | x-=y, Equate to x=x-y |
*= | x*=y, Equate to x=x*y |
/= | x/=y, Equate to x=x/y |
%= | x%=y, Equate to x=x%y, Express and seek x Divide y The remainder of |
++ | x++ or ++x, Equate to x=x+1 |
– | x-- or --x, Equate to x=x-1 |
4.8、 Operator precedence
Operator | associativity |
---|---|
.( spot )、()( parentheses )、[]( brackets ) | From left to right |
+ ( just )、-( negative )、++ ( Self increasing )、–( Self reduction )、~( Bitwise non )、!( Logic is not ) | From right to left |
* ( ride )、/ ( except )、% ( Remainder ) | From left to right |
+ ( Add )、-( reduce ) | From left to right |
<<、>>、>>> | From left to right |
<、<=、>、>= | From left to right |
==、!= | From left to right |
& | From left to right |
| | From left to right |
^ | From left to right |
&& | From left to right |
|| | From left to right |
?: | From right to left |
=、+=、-=、*=、/=、%=、&=、 | =、^=、~=、<<=、>>=、>>>= |
5、 Variables and constants
Examples of variable use
class Program
{
static void Main(string[] args)
{
int num1 = 100;
double num2 = 100.123;
bool isFlag = true;
String name = "Hello";
// Variable conversion
int temp;
temp = a;
a = b;
b = temp;
}
}
const The variables defined are constants , The value cannot be changed after the first assignment
static void Main(string[] args)
{
const double PI = 3.14;
}
6、 Naming rules
Variable name : Hump named , The first letter of the first word is lowercase .
Name of constant : All capitals .
The name of the class : title case , Such as Student.
Name of interface : It's usually based on I start , The second letter is also capitalized , Such as ICompare.
Method name : title case , Usually use verbs , Such as AddUser.
边栏推荐
- How the computer flushes the local DNS cache
- 在恒泰证券开户怎么样?安全吗?
- Learning methods of zynq
- Buuctf, misc: sniffed traffic
- What are the common computer problems and solutions
- Pat grade A - 1164 good in C (20 points)
- How about agricultural futures?
- . Net ADO splicing SQL statement with parameters
- Pooling idea: string constant pool, thread pool, database connection pool
- C3p0 connection MySQL 8.0.11 configuration problem
猜你喜欢
Data consistency between redis and database
Unsafe and CAS principle
string
How to switch between dual graphics cards of notebook computer
The difference between SRAM and DRAM
Format cluster and start cluster
Pyqt5 sensitive word detection tool production, operator's Gospel
To rotate 90 degrees clockwise and modify the video format
320. Energy Necklace (ring, interval DP)
Learning notes of raspberry pie 4B - IO communication (SPI)
随机推荐
Scratch uses runner Py run or debug crawler
Shiftvit uses the precision of swing transformer to outperform the speed of RESNET, and discusses that the success of Vit does not lie in attention!
Go error collection | talk about the difference between the value type and pointer type of the method receiver
webAssembly
Comparable interface and comparator interface
X Opencv feature point detection and matching
Schematic diagram of crystal oscillator clock and PCB Design Guide
File copy method
Buuctf, misc: sniffed traffic
How the computer flushes the local DNS cache
LeetCode 540. A single element in an ordered array
Codeforces Round #768 (Div. 1)(A-C)
Blue Bridge Cup -- Mason prime
How to understand the gain bandwidth product operational amplifier gain
Bufferpool caching mechanism for executing SQL in MySQL
How can enterprises and developers take advantage of the explosion of cloud native landing?
Common mode interference of EMC
33 restrict the input of qlineedit control (verifier)
Qtoolbutton available signal
Recursion and recursion