Difference: 1. The var keyword in JavaScript can refer to different types, but not in C#; 2. JS has 6 basic data types and 1 reference data type, while C# has 16 predefined types and user-defined types; 3. String is a value (basic) type in JS, but is a reference (complex) data in C#.
The operating environment of this tutorial: windows7 system, javascript1.8.5&&C# version 8, Dell G3 computer. The difference between
c# and JavaScript
1. In the var keyword
// C#中
var total = 15;
var mec = new MyExcellentClass();
// 等价于
int total = 15;
MyExcellentClass mec = new MyExcellentClass();
Copy after login
C#, The var keyword is not a symbol for a specific type of variable. It's just syntactic shorthand for any type that can be inferred from the right-hand side of an initialization statement. It is not like the var of js that can refer to different types. The var keyword does not change the strong type nature of C#.
2. Local variables in nested blocks
// C#
void Method
{
var num1 = 5;
{
var num2 = 10;
...
}
...
}
Copy after login
// JS
function Method1()
{
var num1 = 5;
{
var num2 = 10;
...
}
...
}
// 采用es6的let变量
function Method2()
{
let num1 = 5;
{
let num2 = 10;
...
}
...
}
Copy after login
First of all, js did not have the concept of block-level scope before es6. That is to say, in function Method1, both num1 and num2 are in the same scope (that is, the function scope of Method1).
The let variable in es6 enables js to achieve the effect of block scope, that is, the variable num2 only exists in the adjacent pair of braces { }. At this time, the effect of the variable is the same as that of C#'s nested block .
Secondly, there is another difference. In JS, C and C, variables can be renamed. In the internal scope (block scope), the internal name masks the external name, and the value of the variable with the same name is renamed. Set. However, variables with the same name are not allowed in C# (regardless of nesting level, you cannot declare another local variable with the same name within the valid scope of the first name).
Finally, let me expand on this. Unlike JS, C, and C, there are no global variables or global functions in C#. Variables and functions must be declared inside the type (everything is in a class).
3. Data types
JS data types: 6 basic data types and 1 reference data type.
The above is the detailed content of What is the difference between c# and JavaScript. For more information, please follow other related articles on the PHP Chinese website!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The difference between multithreading and asynchronous is that multithreading executes multiple threads at the same time, while asynchronously performs operations without blocking the current thread. Multithreading is used for compute-intensive tasks, while asynchronously is used for user interaction. The advantage of multi-threading is to improve computing performance, while the advantage of asynchronous is to not block UI threads. Choosing multithreading or asynchronous depends on the nature of the task: Computation-intensive tasks use multithreading, tasks that interact with external resources and need to keep UI responsiveness use asynchronous.