Tag: C#的

我应该明确地施放malloc()的返回值吗?

我想问一下下面的情况: char *temp; temp = malloc(10); 由于malloc的返回types是void* , malloc返回的指针是否会在被分配给temp之前被隐式转换为char*types? 标准在这方面说了什么? 如果我们的指针variables是一些结构types,例如: struct node *temp; temp = (struct node *)malloc(sizeof(struct node)); 如果我们将内存分配给temp而不将其转换为struct node*types,是否将其隐式转换为struct node*types,还是需要将其显式转换为struct node* type?

char数组声明中的stringstring大括号有效吗? (如char s = {“Hello World”})

意外的发现,行char s[] = {"Hello World"}; 是正确的编译,似乎被视为与char s[] = "Hello World"; 。 不是第一个( {"Hello World"} )一个包含一个char数组元素的数组,所以s的声明应该读取char *s[] ? 事实上,如果我把它改为char *s[] = {"Hello World"}; 编译器也会接受它,如预期的那样。 寻找一个答案,唯一的地方,我发现这是提到这一个,但没有引用的标准。 所以我的问题是,为什么行char s[] = {"Hello World"}; 编译虽然左侧的array of chartypesarray of char和右侧array of array of chartypes? 以下是一个工作计划: #include<stdio.h> int main() { char s[] = {"Hello World"}; printf("%s", s); // Same output if line […]

C编程:如何将整个文件内容读入缓冲区

我想将一个文件的全部内容写入一个缓冲区。 该文件实际上只包含一个string,我需要比较一个string。 什么是最有效的select,即使在Linux上也是可移植的。 ENV:Windows

如何删除所有在c + +string中出现的字符

我正在使用以下内容: replace (str1.begin(), str1.end(), 'a' , '') 但是这是编译错误。

域对象,POCO和实体有什么区别?

我在印象之下他们都基本一样。 模型对象是否也是一样的? 现在,在我的架构中,我有: class Person { public string PersonId; public string Name; public string Email; public static bool IsValidName() { /* logic here */ } public static bool IsValidEmail() { /* logic here */ } } class PersonService { private PersonRepository pRepository; PersonService() { pRepository = new PersonRepository(); } public bool IsExistingEmail(string email) { //calls […]

为什么string可以分配给char *指针,而不是char 数组?

有人可以解释为什么这与指针工作: char * str1; str1 = "Hello1"; str1 = "new string"; // but not this char str2 [] = "hello"; str2 = "four"; // or this char str3 []; str3 = "hello"; str3 = "hello";

为什么ObjectStateManager属性不存在于我的数据库上下文中?

我需要从我的数据库上下文返回新添加的对象列表。 我读过,我必须使用ObjectStateManager这个目的。 问题是,我的数据库上下文没有ObjectStateManager属性。 上下文工作正常回溯,添加和更新对象虽然。 我正在使用EF 5.0 <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 我能做什么?

如何在.NETtesting中传递一个模拟的HttpClient?

我有一个服务使用Microsoft.Net.Http来检索一些Json数据。 大! 当然,我不希望我的unit testing打到实际的服务器(否则,这是一个集成testing)。 这是我的服务ctor(它使用dependency injection…) public Foo(string name, HttpClient httpClient = null) { … } 我不知道我怎么可以嘲笑…说… Moq或FakeItEasy 。 我想确保当我的服务调用GetAsync或PostAsync ..然后我可以伪造这些调用。 任何build议我怎么能做到这一点? 我是 – 希望 – 我不需要做我自己的包装..因为这是废话:(微软不能做出这个疏忽,对吧? (是的,制作包装纸很容易..我之前做过这些,但这是重点!)

entity framework6事务回滚

用EF6你有一个新的交易,可以像这样使用: using (var context = new PostEntityContainer()) { using (var dbcxtransaction = context.Database.BeginTransaction()) { try { PostInformation NewPost = new PostInformation() { PostId = 101, Content = "This is my first Post related to Entity Model", Title = "Transaction in EF 6 beta" }; context.Post_Details.Add(NewPost); context.SaveChanges(); PostAdditionalInformation PostInformation = new PostAdditionalInformation() { PostId = (101), […]

XElement的孩子

我怎样才能得到XElement的孩子? 我目前正在使用XElement.Descendants()函数,它返回所有级别的XElements,而不仅仅是子节点。 我真正喜欢的是一个IEnumerable只是孩子。