当前位置:网站首页>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.
边栏推荐
- The difference between SRAM and DRAM
- Get current JVM data
- How to restore the factory settings of HP computer
- How about agricultural futures?
- Creation of the template of the password management software keepassdx
- ADB command to get XML
- QT creator source code learning note 05, how does the menu bar realize plug-in?
- 4 environment construction -standalone ha
- [sg function] lightoj Partitioning Game
- How to understand the gain bandwidth product operational amplifier gain
猜你喜欢
Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet
1068. Consolidation of ring stones (ring, interval DP)
The 2022 global software R & D technology conference was released, and world-class masters such as Turing prize winners attended
How to solve win10 black screen with only mouse arrow
Teach you how to run two or more MySQL databases at the same time in one system
Bufferpool caching mechanism for executing SQL in MySQL
Runtime. getRuntime(). totalMemory/maxMemory()
Firefox set up proxy server
Programming language (1)
1 Introduction to spark Foundation
随机推荐
33 restrict the input of qlineedit control (verifier)
Buuctf, misc: n solutions
How about opening an account at Hengtai securities? Is it safe?
Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)
1 Introduction to spark Foundation
LeetCode 1646. Get the maximum value in the generated array
QT creator source code learning note 05, how does the menu bar realize plug-in?
Team collaborative combat penetration tool CS artifact cobalt strike
Unity shader visualizer shader graph
Shell script three swordsman awk
X Opencv feature point detection and matching
Sort merge sort
[automation operation and maintenance novice village] flask-2 certification
Gorilla/mux framework (RK boot): add tracing Middleware
[untitled]
finalize finalization finally final
ADB related commands
ADB command to get XML
[golang] leetcode intermediate - alphabetic combination of island number and phone number
. Net ADO splicing SQL statement with parameters