Tag: C#的

关键值对数据结构的最佳实现?

所以我最近一直在用C#开发,所有的generics集合都让我有点困惑。 假设我想要表示一个数据结构,其中树的头部是一个关键值对,然后在这个关键值对下面有一个可选的列表(但不多于这些关键值)。 这会适合吗? public class TokenTree { public TokenTree() { /* I must admit to not fully understanding this, * I got it from msdn. As far as I can tell, IDictionary is an * interface, and Dictionary is the default implementation of * that interface, right? */ SubPairs = new Dictionary<string, string>(); } public […]

我如何初始化一个浮点数的最大/最小值?

我如何硬编码一个浮点数或双精度的绝对最大值或最小值? 我想通过迭代和捕获最大值来search数组的最大/最小值。 花车也有积极和消极的无限,我应该使用这些呢? 如果是这样,我怎么表示在我的代码?

“Col1,Col2sorting”使用entity framework

我需要使用entity framework按2列sorting。 这是怎么做的? return _repository.GetSomething().OrderBy(x => x.Col1 .. Col2)? 即 SELECT * FROM Foo ORDER BY Col1, Col2 / M

如何确保一个类的每个方法先调用其他方法?

我有 : class Foo { public: void log() { } void a() { log(); } void b() { log(); } }; 有没有办法,我可以有每个Foo方法,调用log() ,但没有我必须显式inputlog()作为每个函数的第一行? 我想这样做,以便我可以添加行为,而不必每个函数,并确保调用,并添加新的function,代码会自动添加… 这甚至有可能吗? 我无法想象如何做到这一点与macros的,所以不知道从哪里开始…到目前为止唯一的方法是想添加一个“预构build步骤”,以便在编译前我扫描文件并编辑源代码,但这似乎并不聪明…. 编辑:只是为了澄清 – 我不希望日志()明确调用自己。 它不需要成为class级的一部分。 编辑:我宁愿使用跨平台的工作方法,只使用stl。

在一个向量<double>上使用std :: max_element

我试图使用std::min_element和std::max_element来返回双精度vector中的最小和最大元素。 我的编译器不喜欢我目前正在尝试使用它们,我不明白错误消息。 我当然可以写我自己的程序来find最小/最大值,但我想了解如何使用这些函数。 #include <vector> #include <algorithm> using namespace std; int main(int argc, char** argv) { double cLower, cUpper; vector<double> C; // code to insert values in C not shown here cLower = min_element(C.begin(), C.end()); cUpper = max_element(C.begin(), C.end()); return 0; } 这是编译器错误: ../MIXD.cpp:84: error: cannot convert '__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >' to 'double' in […]

解释这个片段,它可以在不使用if-else或其他比较运算符的情况下find两个整数的最大值?

find两个数字的最大值。 您不应该使用if-else或其他比较运算符。 我在网上公告板上发现这个问题,所以我想我应该问在StackOverflow 示例input:5,10输出:10 我发现这个解决scheme,有人可以帮我理解这些代码行 int getMax(int a, int b) { int c = a – b; int k = (c >> 31) & 0x1; int max = a – k * c; return max; }

允许.NET中唯一项目的集合?

在C#中有一个集合,不会让你添加重复的项目吗? 例如,与愚蠢的类 public class Customer { public string FirstName { get; set; } public string LastName { get; set; } public string Address { get; set; } public override int GetHashCode() { return (FirstName + LastName + Address).GetHashCode(); } public override bool Equals(object obj) { Customer C = obj as Customer; return C != null […]

如何从任意string中创build一个有效的Windows文件名?

我有一个像“Foo:Bar”这样的string,我想用它作为文件名,但在Windows上,文件名中不允许使用“:”字符。 有没有办法将“Foo:Bar”变成“Foo- Bar”之类的东西?

有没有一个标准的方法来编码一个.NETstring为JavaScriptstring在MS Ajax中使用?

我试图在.NET 3.5中使用MS ScriptManager的RegisterStartUpScript方法将SQL Serverexception的输出传递给客户端。 这适用于某些错误,但是当exception包含单引号时,警报将失败。 我不想只逃避单引号。 有没有一个标准的函数,我可以调用转义任何特殊的字符用于JavaScript? string scriptstring = "alert('" + ex.Message + "');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", scriptstring , true); 编辑 : 感谢@ tpeczek,代码几乎为我工作:)但略有修改(逃避单引号)它的作品。 我在这里包括我的修改版本… public class JSEncode { /// <summary> /// Encodes a string to be represented as a string literal. The format /// is essentially a JSON string. /// /// The string […]

如何快速在我的EDMX模型中find特定的表格?

我想知道是否有人知道在EDMX模型中查找表格的快捷方式,而不是滚动查看图表并寻找相应的东西。 我们的数据库里面有大约50张表格,当我在寻找一个特定的表格时,看到VS把这东西放在哪里只是一件苦差事。 我正在使用VS 2010作为这个问题的目的。 先谢谢你。