这段小代码应该启动并给我正确的变量,但无论变量"numericDay"中的是什么,变量"后缀"给我"th".我不明白为什么当"numericDay"的值都变为字符串变量时它不会改变.
Select Case numericDay
Case numericDay = "1" Or "21" Or "31"
suffix = "st"
Case numericDay = "2" Or "22"
suffix = "nd"
Case numericDay = "3" Or "23"
suffix = "rd"
Case Else
suffix = "th"
End Select
Run Code Online (Sandbox Code Playgroud) 我发现允许修改值类型中的迭代器方法this.
但是,由于CLR的限制,调用方法看不到修改.(this按值传递)
因此,迭代器和非迭代器中的相同代码会产生不同的结果:
static void Main() {
Mutable m1 = new Mutable();
m1.MutateWrong().ToArray(); //Force the iterator to execute
Console.WriteLine("After MutateWrong(): " + m1.Value);
Console.WriteLine();
Mutable m2 = new Mutable();
m2.MutateRight();
Console.WriteLine("After MutateRight(): " + m2.Value);
}
struct Mutable {
public int Value;
public IEnumerable<int> MutateWrong() {
Value = 7;
Console.WriteLine("Inside MutateWrong(): " + Value);
yield break;
}
public IEnumerable<int> MutateRight() {
Value = 7;
Console.WriteLine("Inside MutateRight(): " + Value);
return new int[0];
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
Inside …
我想编写一个在Windows Azure上运行的ASP.Net MVC应用程序,它将使用WPF创建图像.
在我开始编写它之前,它会起作用吗?
Azure是否具有渲染WPF所需的DLL(包括DirectX)和图形处理能力?
(我还没有Azure帐户,所以我不能试试)
例如.
当我试图写下面的东西,在句子中使用撇号,
print(''I am jack's raging bile duct'')
Run Code Online (Sandbox Code Playgroud)
我得到无效的语法错误.如何解决这个问题?
有没有办法在Firefox中获得MSDN搜索栏,它将自动完成.Net类和成员名称(最好也是Win32 API方法)并直接带我到MSDN页面?
使用Shift + Enter的Google工具栏(我很幸运)通常会直接转到.Net类的msdn页面,但它没有目标自动完成功能.此外,由于我懒得键入site:msdn.microsoft.com,它并不总是把我带到MSDN.(例如Graphics)
为什么这样做?我不是在抱怨,只是想知道.
void Test()
{
int a = 1;
int b = 2;
What<int>(a, b);
// Why does this next line work?
What(a, b);
}
void What<T>(T a, T b)
{
}
Run Code Online (Sandbox Code Playgroud) 在Java中,我可以使用通配符"?"指定泛型.可以像这样创建一个地图:
Map<String, ?>.
我正在使用C#,我需要一个Dictionary<String, SomeInterface<?>>(在哪里?可以是int,double,任何类型).这可能在C#中吗?
编辑:
例:
interface ISomeInterface<out T>{
T Method();
void methodII();
}
class ObjectI : ISomeInterface<int>{
...
}
class ObjectII : ISomeInterface<double>{
...
}
class ObjectIII : ISomeInterface<string>{
....
}
Run Code Online (Sandbox Code Playgroud)
我试图将这些对象映射到Dictionary中,如:
Dictionary<String, ISomeInterface<?>> _objs = new Dictionary<String, ISomeInterface<?>();
_objs.Add("Object1", new ObjectI());
_objs.Add("Object2", new ObjectII());
_objs.Add("Object3", new ObjectII());
foreach(var keyVal in _objs){
Console.WriteLine(keyVal.Method());
}
Run Code Online (Sandbox Code Playgroud)
使用Assembly和Activator.createInstance在运行时加载实现ISomeInterface的对象.在创建的那一刻,我不会,如果对象实现 ISomeInterface<int>或ISomeInterface<double>.
很感谢任何形式的帮助.
当我添加如下图标时:
etComment = (EditText) findViewById(R.id.et_comment);
Drawable img = getResources().getDrawable( R.drawable.warning );
etComment.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null );
Run Code Online (Sandbox Code Playgroud)

图标调整EditText的大小.如何在不调整EditText大小的情况下计算img大小并将其放入EditText?
谢谢!
FunkTheMonk
使用setCompounDrawables()而不是setCompoundDrawablesWithIntrinsicBounds() - 您必须手动设置drawable的边界.
我不明白如何手动计算Bounds.我有EditText的高度和宽度:
etComment = (EditText) findViewById(R.id.et_comment);
Drawable img = getResources().getDrawable( R.drawable.warning );
int size = etComment.getHeight();
img.setBounds(0, 0, size, size);
etComment.setCompoundDrawables( img, null, null, null );
Run Code Online (Sandbox Code Playgroud)
但我在不同的屏幕尺寸上有不同的结果.我如何计算图标的正确尺寸和填充?请你帮助我好吗?
由于我不知道我的问题是如何被调用的,我不能保证,没有人最近或根本没有问过同样的问题.
我注意到,但是有很多线程具有相似的标题,但它们似乎与我的问题无关.
我有一个自定义列表类,它实现了泛型.
class MyList<T>
{
public void add(T item) // adds an item to the list
{ /* code */ }
public void add(MyList<T> list) // attaches an existing list to the end of the current one
{ /* code */ }
}
Run Code Online (Sandbox Code Playgroud)
我也有课程:
class Apple : Fruit
Run Code Online (Sandbox Code Playgroud)
和
class Banana : Fruit
Run Code Online (Sandbox Code Playgroud)
现在,相关代码:
MyList<Fruit> fruitList = new MyList<Fruit>();
// fill fruitList
fruitList.add(new Apple()); // works, of course
fruitList.add(new Banana()); // works as well, of course
MyList<Apple> appleList = …Run Code Online (Sandbox Code Playgroud)