在某些块中创建一个匿名对象和"弱链接"中的对象:
//first object System.Random
string result = new Random().Next(0,1) == 1 ?
"equal 1":"sory, but not equal 1";
//second object System.Random
string result = ((Random)new WeakReference(new Random()).Target).Next(0,1) == 1 ?
"equal 1":"sory, but not equal 1";
GC.Collect();
Run Code Online (Sandbox Code Playgroud)
在垃圾收集后,哪个评论标记对象有更大的机会保持活力?
可以将字典中的第一种类型设为引用类型吗?如果是,那是什么意思?
using System.Collections.Generic;
...
Dictionary<T1, T2> myDict = new Dictionary<T1, T2>();
Run Code Online (Sandbox Code Playgroud)
据我了解,第一种类型 - 是关键。并且比int或string类型更常见。
据我所知,使用private修饰符,您只能从类继承,但不能创建它的实例.
private class A // error
{
}
class B
{
static int Main()
{
A obj = new A();
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
这是私人课程唯一有用的功能吗?
我在Unity3d上有一个游戏,我使用JS(UnityScript)和C#编写脚本.在JS脚本中,我有一个变量,我需要在C#脚本中访问它.
可以这样做吗?
的script.js:
public var myVarible;
Run Code Online (Sandbox Code Playgroud)
Script.cs:
class A {
void B() {
Script script; // Compiler can't see Script
script = GameObject.Find ("MyScripts").GetComponent<Script> ();
script.myVariable = false;
}
}
Run Code Online (Sandbox Code Playgroud) 任何人都可以解释,为什么大小objC是8,而不是12?
我认为,如果在课堂上C我有对象类型int和A,B- char,然后创作之后objC它应该是4个字节objA,objB和ObjC.
class A {
char a;
};
class B : A {
char b;
};
class C : B {
int c;
};
int main()
{
A objA;
B objB;
C objC;
cout << sizeof(objA) << endl; // 1
cout << sizeof(objB) << endl; // 2
cout << sizeof(objC) << endl; // 8! Why not 12?
return 0;
} …Run Code Online (Sandbox Code Playgroud) 此方法返回false.我不明白为什么
private bool SomeMethod()
{
return new byte[0] == new byte[0];
}
Run Code Online (Sandbox Code Playgroud) 是什么让这种结构?
int a[10];
int x;
x = 2[a];
Run Code Online (Sandbox Code Playgroud)
我不明白是什么让2 [a].这是C语言的另一种衰老?
有人可以意识到这种结构有什么意义吗?
public class A
{
public A(): this("..") {}
}
Run Code Online (Sandbox Code Playgroud) 没有Thread.Sleep线程的原因是异步工作(1),还是同步(2)?
class A
{
static object locker = new object();
static void M0()
{
for(int i = 0; i < 5; i++)
lock (locker)
{
Console.WriteLine("Secondary");
//Thread.Sleep(100);
}
}
static void Main()
{
ThreadStart ts = new ThreadStart(M0);
Thread t = new Thread(ts);
t.Start();
for (int i = 0; i < 5; i++)
lock (locker)
{
Console.WriteLine("Primary");
//Thread.Sleep(100);
}
}
}
Run Code Online (Sandbox Code Playgroud) 有两个相同的功能.一个用const关键字和另一个接受参数- 没有.
void A(const int* p);
void A(int* p);
int main()
{
int x;
A(&x);
return 0;
}
void A(const int* p)
{
cout << "2" << endl;
}
void A(int* p)
{
cout << "1" << endl;
}
Run Code Online (Sandbox Code Playgroud)
如何使这段代码更简单?
if (PlayersLevel > 1)
button4.Visible = true;
else
button4.Visible = false;
if (PlayersLevel > 2)
button5.Visible = true;
else
button5.Visible = false;
Run Code Online (Sandbox Code Playgroud)
好的,好的,我已经知道了=)谢谢