Code/Study
[C/C++ vs C#] static (1)
Hide Code
2008. 7. 16. 21:15
< C/C++ >
function 내부에서 static variable 선언 가능
< C# >
method 내부에서 static variable 선언 불가능
static field 선언 가능
function 내부에서 static variable 선언 가능
#include <stdio.h>
void main()
{
static int i = 0; // valid
}
void main()
{
static int i = 0; // valid
}
< C# >
method 내부에서 static variable 선언 불가능
static field 선언 가능
using System;
namespace Sample
{
class Program
{
static void Main(string[] args)
{
static int i = 0; // compile time error
}
private static int number = 0; // valid
}
}
namespace Sample
{
class Program
{
static void Main(string[] args)
{
static int i = 0; // compile time error
}
private static int number = 0; // valid
}
}