질문:C\#연속 할당 에 기반 한 면접 문제(해답)
:질문:C\#연속 할당 에 기반 한 면접 문제 소개 msdn , = :
( =) 、 , 。
( )。
int x,y,z;X = y = z = 1;
1:z=1, 1 z, 1,
2:y=(z=1), 1 y, 1,
3:x=(y=(z=1)), 2 1 x。
:
const int x=1;short y;object z;z=y=x;
.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; } x const, const ,
Z=y=x; z=y=1。
1:y=1, y short, 1 short, 1(short);
2: y=1 , 1(short) z, z 1(short) ,
GetType System.Int16.
, const int x=1 const , :
int x=1;short y;object z;z=y=x;
.csharpcode, .csharpcode pre{font-size: small;color: black;font-family: consolas, "Courier New", courier, monospace;background-color: #ffffff;/*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt {background-color: #f4f4f4;width: 100%;margin: 0em;}.csharpcode .lnum { color: #606060; } x Int32,y Int16, Int32 Int16. :
:
class C
{
private string x;
public string X
{
get { return x ?? ""; }
set { x = value; }
}
}
static void Main()
{
C c = new C();
object z;
z = c.X = null;
//
System.Console.WriteLine(z == null);
System.Console.WriteLine(c.X == null);
}
관건 은 분석:z=c.X=null;1:c.X=null;c 의 setX 방법 을 호출 하여 x=null 을 설정 하고 null 을 값 으로 되 돌려 줍 니 다.
2:z=(c.X=null);c.X=null 이 null 로 되 돌 아 왔 기 때문에 null 을 z 에 할당 합 니 다.z 는 null 입 니 다.
3:Console.WriteLine(z=null),true 로 돌아 가기;
4:Console.Write Line(c.X=null),c 의 getX 방법 을 호출 하여 방법 을 되 돌려 줍 니 다.
잘 했 어?
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.