Tag: C#的

在比较C ++中的结构时找不到==操作符

比较以下结构的两个实例,我收到一个错误: struct MyStruct1 { Position(const MyStruct2 &_my_struct_2, const int _an_int = -1) : my_struct_2(_my_struct_2), an_int(_an_int) {} std::string toString() const; MyStruct2 my_struct_2; int an_int; }; 错误是: 错误C2678:二进制'==':没有find操作符,它需要一个types为'myproj :: MyStruct1'的左手操作数(或没有可接受的转换) 为什么?

Html.EditorFor设置默认值

菜鸟问题。 我有一个parameter passing给创build视图。 我需要设置一个默认值的字段名称。 @ Html.EditorFor(model => model.Id)我需要设置这个input字段的名称Id与默认值,通过一个动作链接传递给视图。 那么,这个input字段(@ Html.EditorFor(model => model.Id))如何被设置为一个默认值。 下面的工作? 数字5是一个参数,我传递到文本字段设置默认值。 @Html.EditorFor(c => c.PropertyName, new { text = "5"; })

在代码中设置保证金属性

MyControl.Margin.Left = 10; 错误: 无法修改“System.Windows.FrameworkElement.Margin”的返回值,因为它不是一个variables

在C#ASP.NET中获取完整的查询string

作为一个PHP程序员,我习惯于使用$ _GET来检索HTTP查询string…如果我需要整个string,那么加载的方式来做到这一点。 但在ASP中,我似乎无法得到查询。 这里是news.aspx的代码(embedded在一些HTML中): <% string URL = "http://www.example.com/rendernews.php?"+Request.Querystring; System.Net.WebClient wc = new System.Net.WebClient(); string data = wc.DownloadString(URL); Response.Output.Write(data); %> 我从远程服务器获取一个PHP脚本的输出,这完全没有Request.Querystring。 问题是,我试图在第一行得到完整的查询string:Request.Querystring。 我得到一个错误“ 对象引用未设置为对象的实例 ”,这基本上意味着Request.Querystring不存在。 任何想法是什么问题在这里? 我怎样才能得到该查询string,所以当index.aspx被调用像http://test.com/news.aspx?id=2我的脚本提取http://www.example.com/rendernews.php?id=2

在C#将匿名types转换为键/值数组?

我有以下匿名types: new {data1 = "test1", data2 = "sam", data3 = "bob"} 我需要一个方法将这个,并在数组或字典中输出键值对。 我的目标是使用这个作为HttpRequest中的发布数据,所以我最终将连接到以下string: "data1=test1&data2=sam&data3=bob"

{}在C#中创build新对象时的行为如何()

我只注意到,使用{}而不是()在构造对象时会得到相同的结果。 class Customer { public string name; public string ID {get; set;} } static void Main() { Customer c1= new Customer{}; //Is this a constructor? Customer c2= new Customer(); //what is the concept behind the ability to assign values for properties //and fields inside the {} and is not allowable to do it inside () […]

在c ++中“::”“。”和“ – >”有什么区别?

可能重复: 什么时候使用点,箭头或双冒号引用C ++中的类的成员? 我创build了一个叫Kwadrat的类,里面有三个int字段。 代码块给了我build议,我可以通过:: ,进入对象的领域. 和-> 。 箭是唯一的工作,但为什么? 这三者有什么区别? #include <iostream> using namespace std; class Kwadrat{ public: int val1, val2, val3; Kwadrat(int val1, int val2, int val3) { this->val1 = val1; //this.val2 = val2; //this::val3 = val3; } }; int main() { Kwadrat* kwadrat = new Kwadrat(1,2,3); cout<<kwadrat->val1<<endl; cout<<kwadrat->val2<<endl; cout<<kwadrat->val3<<endl; return 0; }

如何使用IEqualityComparer

我的数据库中有一些相同的号码。 我想让所有这些都不重复。 然后我创build一个比较类来完成这个工作,但是函数的执行会使得函数有一个很大的延迟,从0.6秒到3.2秒没有区别! 我是对的还是要用另一种方法? reg.AddRange((from a in this.dataContext.reglements join b in this.dataContext.Clients on a.Id_client equals b.Id where a.date_v <= datefin && a.date_v >= datedeb where a.Id_client == b.Id orderby a.date_v descending select new Class_reglement { nom = b.Nom, code = b.code, Numf = a.Numf, }).AsEnumerable().Distinct(new Compare()).ToList()); class Compare : IEqualityComparer<Class_reglement> { public bool Equals(Class_reglement x, […]

从函数返回Cstring

我想从一个函数返回一个Cstring,但它不工作。 这是我的代码。 char myFunction() { return "My String"; } 主要我这样称呼它: int main() { printf("%s",myFunction()); } 我也尝试了一些其他的方式myFunction但他们不工作。 例如: char myFunction() { char array[] = "my string"; return array; } 注意:我不允许使用指针! 关于这个问题的小背景:有找出它是哪个月份的函数。 如果它的1则返回1月等等 所以当它打印时,就是这样做的。 printf("Month: %s",calculateMonth(month)); 。 现在的问题是如何从calculateMonth函数返回该string。

C#中的空参数检查

在C#中,是否有任何很好的理由(除了一个更好的错误消息)添加参数空检查每个函数的空值不是一个有效的值? 显然,使用s的代码无论如何都会抛出exception。 而这样的检查使代码变得越来越难以维护。 void f(SomeType s) { if (s == null) { throw new ArgumentNullException("s cannot be null."); } // Use s }