当前位置:网站首页>C#的变量
C#的变量
2022-06-12 17:53:00 【锄禾吖】
C#的变量只不过是一个供程序操作的存储区的名字。在 C# 中,每个变量都有一个特定的类型,类型决定了变量的内存大小和布局。范围内的值可以存储在内存中,可以对变量进行一系列操作。
在这里,data_type 必须是一个有效的 C# 数据类型,可以是 char、int、float、double 或其他用户自定义的数据类型。variable_list 可以由一个或多个用逗号分隔的标识符名称组成。
一些有效的变量定义如下所示:
int i, j, k;
char c, ch;
float f, salary;
double d;
可以在变量定义时进行初始化:
int i = 100;
变量可以在声明时被初始化(指定一个初始值)。初始化由一个等号后跟一个常量表达式组成,如下所示:
< data_type > < variable_name > = value;
还有一些实例:
int d = 3, f = 5; /* 初始化 d 和 f. */
byte z = 22; /* 初始化 z. */
double pi = 3.14159; /* 声明 pi 的近似值 */
char x = 'x'; /* 变量 x 的值为 'x' */
正确地初始化变量是一个良好的编程习惯,否则有时程序会产生意想不到的结果。请看下面的实例,使用了各种类型的变量:
namespace cs
{
class Program
{
static void Main(string[] args)
{
short a;
int b;
double c;
/* 实际初始化 */
a = 10;
b = 20;
c = a + b;
Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c);
}
}
}
当上面的代码被编译和执行时,它会产生下列结果:
边栏推荐
- 使用MongoDB官方go库操作MongoDB原创
- WinForm, crystal report making
- Common dependencies of SSM
- 电控学习 第二周
- 进阶之大山-asp.net core 路由程序基础使用演示0.1
- bug记录:更新数据库时报错:Data truncation: Incorrect datetime value:
- DRM 驱动 mmap 详解:(一)预备知识
- Kali2022安装armitage
- Make good use of IDE, speed up R & D efficiency by 100%
- Hangzhou AI developer meetup registration opens!
猜你喜欢

Risc-v ide mounriver studio v1.60 update point introduction

小程序+App,低成本获客及活跃的一种技术组合思路

Article name
![[csp]202012-2 optimal threshold for period end forecast](/img/40/9b59bd692bcfe05d16614cc6d55d1f.png)
[csp]202012-2 optimal threshold for period end forecast

An easy-to-use IDE for small programs
![[CSP]202012-2期末预测之最佳阈值](/img/40/9b59bd692bcfe05d16614cc6d55d1f.png)
[CSP]202012-2期末预测之最佳阈值

Cesium parabolic equation

JDBC几个坑

vant3+ts DropdownMenu 下拉菜单,数据多能滚动加载

A method of quickly reusing wechat login authorization in app
随机推荐
Stream流注意点
全局锁、表锁、行锁
企业架构的第一性原理
Error record: illegalstateexception: optional int parameter 'XXXX' is
Tensorflow reads data from the network
使用MongoDB官方go库操作MongoDB原创
Understanding of binary search
118. Yanghui triangle (dynamic planning)
Common dependencies of SSM
Hangzhou AI developer meetup registration opens!
SSM integrates FreeMarker and common syntax
Tensorflow prompts typeerror: unsupported operand type (s) for *: 'float' and 'nonetype‘
Tcp/ip family structure and protocol of tcp/ip series overview
Graphical data model for system design
重构--梳理并分解继承体系
Figma从入门到放弃
Authorization in Golang ProjectUseing Casbin
Vulnhub[DC3]
Soringboot下RestTemplateConfig 配置打印请求响应日志
566. reshaping the matrix