Tag: C#的

带定时器的Windows服务

我用c#.net中的计时器创build了一个windows服务。 它工作正常,而我在Visual Studio中debugging/build立项目,但安装后不执行它的操作。 这背后的原因是什么? 代码: public partial class Service1 : ServiceBase { FileStream fs; StreamWriter m_streamWriter; Timer tm = new Timer(); public Service1() { InitializeComponent(); this.ServiceName = "timerservice"; tm.Interval = 2000; tm.Tick += new EventHandler(PerformOperations); tm.Start(); fs = new FileStream(@"c:\mcWindowsService.txt", FileMode.OpenOrCreate, FileAccess.Write); m_streamWriter = new StreamWriter(fs); m_streamWriter.BaseStream.Seek(0, SeekOrigin.End); } private void PerformOperations(object sener, EventArgs e) […]

如何通过cout输出一个字符为整数?

#include <iostream> using namespace std; int main() { char c1 = 0xab; signed char c2 = 0xcd; unsigned char c3 = 0xef; cout << hex; cout << c1 << endl; cout << c2 << endl; cout << c3 << endl; } 我预计输出如下: ab cd ef 然而,我什么也没得到。 我猜这是因为cout总是把'char','signed char'和'unsigned char'视为字符而不是8位整数。 然而,'char','signed char'和'unsigned char'都是整型。 所以我的问题是:如何通过cout输出一个字符为整数? PS:static_cast(…)是丑陋的,需要更多的工作来修剪额外的位。

使用函数指针的STL映射

我开发了一个拥有许多内置函数的脚本引擎,所以要调用任何函数,我的代码就进入了if .. else if .. else if检查名称的墙,但我想开发一个更有效的解决scheme。 我应该使用散列表与string作为键和指针作为值? 我怎么能通过使用STL地图呢? 编辑 :进入我的脑海的另一点:当然使用地图将强制编译器不内联函数,但我低效率的方法没有任何开销产生的function调用的必要性,它只是执行代码。 所以我想知道函数调用产生的开销是否会比使用if..else链更好。否则,我可以通过在运行时检查一个字符来最小化比较次数(将会更长但更快)。

将对象序列化为JSON时,循环引用检测到exception

就像在这篇文章中提到的,我在序列化entity framework代理的时候遇到了一个Json序列化错误: 序列化“System.Data.Entity.DynamicProxies.PurchaseOrder_446B939192F161CDBC740067F174F7A6059B0F9C0EEE68CD3EBBD63CF9AF5BD0”types的对象时检测到循环引用。 但是区别在于,我的实体中没有循环引用, 只有在我们的生产环境中才会出现。 本地一切工作正常… 我的实体: public interface IEntity { Guid UniqueId { get; } int Id { get; } } public class Entity : IEntity { public int Id { get; set; } public Guid UniqueId { get; set; } } public class PurchaseOrder : Entity { public string Username { get; set; […]

如何使用Newtonsoft JSON.NET将JSON反序列化为IEnumerable <BaseType>

给这个JSON: [ { "$id": "1", "$type": "MyAssembly.ClassA, MyAssembly", "Email": "me@here.com", }, { "$id": "2", "$type": "MyAssembly.ClassB, MyAssembly", "Email": "me@here.com", } ] 和这些类: public abstract class BaseClass { public string Email; } public class ClassA : BaseClass { } public class ClassB : BaseClass { } 我如何反序列化JSON到: IEnumerable<BaseClass> deserialized; 我不能使用JsonConvert.Deserialize<IEnumerable<BaseClass>>()因为它抱怨BaseClass是抽象的。

C ++中“free function”这个术语的含义是什么?

在阅读boost :: test的文档时,我遇到了“自由function”这个词。 我所理解的是一个自由函数是任何不返回任何东西的函数(它的返回types是void)。 但是在进一步阅读之后,似乎免费函数也没有任何争论。 但我不确定。 这些都是我的假设。 那么有人可以定义自由function吗?

M在C#中代表什么?十进制文字符号?

为了处理十进制数据types,我必须在variables初始化的时候这样做: decimal aValue = 50.0M; M部分代表什么?

C#获取没有扩展名的文件名

在某个文件夹中获取文件名时: DirectoryInfo di = new DirectoryInfo(currentDirName); FileInfo[] smFiles = di.GetFiles("*.txt"); foreach (FileInfo fi in smFiles) { builder.Append(fi.Name); builder.Append(", "); … } 通过fi.Name我们得到一个扩展名为file1.txt , file2.txt , file3.txt的文件名 如何获得没有文件扩展名file1 , file2 , file3文件名?

NULL + int的结果是什么?

我已经看到在OpenGL VBO实现中使用下面的macros: #define BUFFER_OFFSET(i) ((char *)NULL + (i)) //… glNormalPointer(GL_FLOAT, 32, BUFFER_OFFSET(x)); 你能否提供一些关于这个macros如何工作的细节? 它可以被replace为一个function? 更确切地说,增加一个NULL指针的结果是什么?

用C语言翻译8个阶段的海报

有没有人有一个海报/单页PDF或类似的与C语言翻译的八个阶段(第一个是三字母翻译)列表类似的吗? 我想有一个印在我的电脑旁边的墙上。 更新:遗忘忘记指定。 我对C90感兴趣(虽然C99可能非常接近, _Pragma Pmg的答案中提到的_Pragma是C99特有的,我想避免这种情况)。