例如
using (Stream ftpStream = ftpResponse.GetResponseStream()) // a
using (FileStream localFileStream = (new FileInfo(localFilePath)).Create()) // b
{
........do something
}
Run Code Online (Sandbox Code Playgroud)
两个陈述a和b会按照我的顺序执行吗?并按顺序排列?
谢谢
我试图使用"使用"最小化实体框架连接上下文范围,而在平均时间我希望能够将一个上下文注入我的类.我在互联网上搜索但是没有找到像我这样的情况,或者我只是做错了什么,无论如何,这里是代码:
[TestFixture]
public class Dummy
{
private IFoo ifoo;
[Test]
public void CreateIfNotExist()
{
using (var foo = GetNewIFoo())
{
foo.Dosomething();
}
Assert.IsNull(ifoo);//test fail here
}
[Test]
public void NotCreateIfExist()
{
ifoo = new Bar();
using (var foo = GetNewIFoo())
{
foo.Dosomething();
}
Assert.IsNull(ifoo);//test fail here
}
private IFoo GetNewIFoo()
{
if (ifoo == null)
{
ifoo = new Foo();//return new Foo();
}
return ifoo;
}
}
Run Code Online (Sandbox Code Playgroud)
第一个测试失败,创建了foo的对象序列 - > foo做某事 - > foo处置(使用on foo调用),而状态变量ifoo仍然是Foo()的类型.
第二次测试失败,对象生命序列与之前相同.
我很困惑因为我认为GetNewIFoo()会返回ifoo的引用而使用关键字只会在ifoo上调用dispose?
另外,有没有什么好方法可以控制上下文范围,同时保持注入IContext的能力?
奇怪的是......这次没有代码但是使用System.ServiceProcess; import在导入的ServiceProcess部分下获得一条红线.
有谁知道为什么?是否有一个替代这个类,以便我仍然可以启动和停止Windows服务?
我正在学校的实验室工作,并在说明中说:
将定义Word_List的typedef更改为别名声明(使用)
从我用Google搜索过的方式来看,改变方法是:
typedef vector<Word_Entry> Word_List;
Run Code Online (Sandbox Code Playgroud)
至:
using Word_List = std::vector<Word_Entry>;
Run Code Online (Sandbox Code Playgroud)
但是当我编译时,我收到以下错误:
error: expected nested-name-specifier before 'Word_List'
Run Code Online (Sandbox Code Playgroud)
大部分代码:
#include <iostream>
#include <algorithm>
#include <list>
#include <string>
#include <vector>
#include <fstream>
#include <cctype>
#include <iomanip>
using namespace std;
struct Word_Entry
{
string ord;
unsigned cnt;
};
//typedef vector<Word_Entry> Word_List; <-This is what it used to look like
using Word_List = vector<Word_Entry>;
int main()
{
...
}
Run Code Online (Sandbox Code Playgroud)
附加信息:
Yes, I am compiling with c++11
Word_Entry is a struct that stores 2 variables …Run Code Online (Sandbox Code Playgroud) 我正在加载Image一个byte[]使用MemoryStream并通过检查它来获取有关图像的信息ProperyItems.在这样做的过程中,我注意到一些奇怪的行为,其中一些图像PropertyItems正在消失.经过多次调试后,我终于发现这是由于MemoryStream被处理造成的.
MemoryStream ms0 = new MemoryStream(imageBytes);
Image img0 = Image.FromStream(ms0);
Console.Out.WriteLine("Without using, Image propertyIDs: ");
foreach (int itemId in img0.PropertyIdList)
Console.Out.Write(itemId + ", ");
Console.Out.Write("\n");
Image img1 = null;
using (MemoryStream ms1 = new MemoryStream(imageBytes))
{
img1 = Image.FromStream(ms1);
}
Console.Out.WriteLine("Outside using, Image propertyIDs: ");
foreach (int itemId in img1.PropertyIdList)
Console.Out.Write(itemId + ", ");
Console.Out.Write("\n");
Run Code Online (Sandbox Code Playgroud)
输出:
Without using, Image propertyIDs:
254, 256, 257, 258, 259, 262, 269, 273, …Run Code Online (Sandbox Code Playgroud) 我的程序中有一个类,我总是要这样访问:
Blah.Blah.Blah.DoSomething();
Run Code Online (Sandbox Code Playgroud)
而且我希望能够访问DoSomething()而无需每次都输入所有这些内容.using Blah;不会编译,也不会出现在Visual Studio的intellisense上.我怎么能做到这一点?
目标是在模板对象中定义一个函数,其中void(void)作为原型.以下代码:
template <class T>
using ClassVoidFunctionPointer = void (T::*)(void);
class Scheduler {
public:
Scheduler(void);
~Scheduler(void);
template <class T>
void addTask(unsigned short interval, unsigned short delay,T templateClass,ClassVoidFunctionPointer classFunctionPtr );//For newer functions
...
}
Run Code Online (Sandbox Code Playgroud)
这给了我错误:
inc/scheduler.h:18:77: error: 'ClassVoidFunctionPointer' is not a type
Run Code Online (Sandbox Code Playgroud)
为什么我会收到此错误?
我正在使用 Visual Studio 2015。
我得到了一个使用一堆第三方 DLL 的项目的源代码。如何找出哪个using语句使用哪个 DLL?
例如我有这样的声明:
using Mnp;
Run Code Online (Sandbox Code Playgroud)
如何找出哪个 DLL 具有Mnp命名空间?
我把光标放在上面Mnp并右键单击以打开右键单击菜单。在那里我尝试了 2 个选项:
但在这两种情况下,我都会收到相同的错误消息:
无法导航到插入符号下的符号。
我希望 Visual Studio 可以在References具有 namespace 的部分中指向我的 DLL Mnp。
谢谢
有谁知道using从 C# 文件中删除未使用语句的自动方法,但保留开发人员指定的某些语句?
我正在尝试将对象保存在非默认数据库中。我已经配置了第二个连接。
我知道为了得到对象,它是 Class.objects.using('the_db').all
但是当我尝试时object.using('the_db').save()它不起作用。(错误:“对象没有属性 'using'”。我也尝试过,object.save('the_db')但它也不起作用。
我怎样才能做到这一点?我找不到正确的语法。