我有以下代码:
public class AppDomainArgs : MarshalByRefObject {
public string myString;
}
static AppDomainArgs ada = new AppDomainArgs() { myString = "abc" };
static void Main(string[] args) {
AppDomain domain = AppDomain.CreateDomain("Domain666");
domain.DoCallBack(MyNewAppDomainMethod);
Console.WriteLine(ada.myString);
Console.ReadKey();
AppDomain.Unload(domain);
}
static void MyNewAppDomainMethod() {
ada.myString = "working!";
}
Run Code Online (Sandbox Code Playgroud)
我想这会让我的ada.myString"工作!" 在主appdomain上,但它没有.我认为通过继承MarshalByRefObject,在第二个应用程序域上所做的任何更改也会反映在原始应用程序中(我认为这只是主appdomain上真实对象的代理!)?
谢谢
在VB.Net中你可以做如下的事情,没有任何问题...只是忽略这是一个非常无用的类的事实:-)
Imports System
Public Class Class1
Public Shared Function ArrayToList(ByVal _array() As String) As Collections.Generic.List(Of String)
Return New Collections.Generic.List(Of String)(_array)
End Function
End Class
Run Code Online (Sandbox Code Playgroud)
但是如果你在C#中做同样的事情......
using System;
public class Class1
{
public static Collections.Generic.List ArrayToList(string[] _array)
{
return new Collections.Generic.List(_array);
}
}
Run Code Online (Sandbox Code Playgroud)
您将在"Collections.Generic.List"返回的行上收到错误,说"找不到类型或命名空间名称'Collections'(您是否缺少using指令或程序集引用?)"
我知道你必须有一个使用System.Collections.Generic的using指令才能使用List,但我不知道为什么.我也不明白为什么我在函数声明中没有得到相同的错误,只是在return语句中.
我希望有人可以解释这一点,甚至可以将我推荐给一个解释它的technet页面.我四处寻找,但找不到任何解释这个概念的东西.
编辑:请注意,问题实际上是关于子命名空间的引用,例如在示例中能够引用系统中的集合.
在vb 2008 express中,此选项在应用程序属性下可用.有谁知道它的功能是什么?这样做是为了不可能同时打开两个实例吗?
我如何在vb.net中使用for循环
dim start as integer
Dim customers as New List(Of Customers)
Customers=dataAcess.GetCustomers()
For each start=500 in Customers.count
'Do something here'
Next
Run Code Online (Sandbox Code Playgroud)
我想为每500个客户处理一些数据..请帮助
我有一个团队,人们对C#非常熟悉,但我们要求在VB.net中编写一个项目.在C#中思考并在飞行中转换为VB有多难?那可行吗?
你能否列出我们可以遇到的问题?
我听说VB.net没有闭包.对于.net 3.5来说,这仍然是真的吗?
你如何获得vb.net中数字的绝对值?
有内置的功能吗?我知道我可以自己编写一个函数,但我想先知道是否已有一个函数.看起来很简单,我可能会用三行来制作它,所以如果没有一行我会感到惊讶....
谢谢!
我using
在C#和VB中都使用了该语句.我同意所有关于使用语句嵌套的批评者(C#似乎做得很好,VB不是那么多)
因此,考虑到这一点,我有兴趣通过在同一块中"使用"多个系统资源来改进我的VB使用语句:
例:
Using objBitmap As New Bitmap(100,100)
Using objGraphics as Graphics = Graphics.From(objBitmap)
End Using
End Using
Run Code Online (Sandbox Code Playgroud)
可写成这样:
Using objBitmap As New Bitmap(100,100), objGraphics as Gaphics = Graphics.FromImage(objbitmap)
End Using
Run Code Online (Sandbox Code Playgroud)
所以我的问题是什么是更好的方法?
我的直觉告诉我,如果资源是相关/依赖的,那么在using语句中使用多个资源是合乎逻辑的.
为了论证,我怎么能在VB中这样做?
foreach foo in bar
{
if (foo == null)
break;
if (foo = "sample")
continue;
// More code
//...
}
Run Code Online (Sandbox Code Playgroud) 如何在VB.NET中按位左右按位移位?它甚至有操作员,还是我必须使用一些实用方法?
C#中有别名功能,允许使用不同的程序集,包含同名的实体(类,结构,枚举).选择装配引用的装配列表时会激活它.但我在VB.NET项目中看不到任何类似的东西.VB.NET中有这样的功能吗?如果不是,为什么?
vb.net ×10
.net ×4
c# ×3
appdomain ×1
bit-shift ×1
c#-to-vb.net ×1
coding-style ×1
for-loop ×1
foreach ×1
operators ×1
remoting ×1
statements ×1
using ×1
winforms ×1