casting

Dynamic linq: Is there a way to access object data by index?

戏子无情 提交于 2019-12-30 10:29:11
问题 I need some in-memory filtering with Dynamic Linq. My objects have only a indexer: public object this[int index] { } The access to my data is like: object[0], object[1],... So my query is like this: // get FilterText from user at runtime // eg. filterText can be: [0] > 100 and [1] = "wpf" collection.AsQueryable().where(filterText); Is there any way to do this? 回答1: I have some news for you. It is actually possible... BUT! (Yes, there´s a but). I assume you are using the dynamic Linq library.

Default Visual Studio Project Settings to Use “rvalueCast”

前提是你 提交于 2019-12-30 10:27:31
问题 I've made a <sarcasm>shocking</sarcasam> discovery: Visual Studio 2015 is not C++11 compliant by default I can follow the steps I listed here for each project, or use Notepad++ or similar to do a files replace, but I do notice that the "Command Line" Properties have a checkbox: "Inherit from parent or project defaults" Is there a way to add "/Zc:rvalueCast" to my "project defaults" so everything will use it, including future projects? 回答1: Edit the microsoft.cpp.win32.user property sheet

Default Visual Studio Project Settings to Use “rvalueCast”

旧城冷巷雨未停 提交于 2019-12-30 10:27:18
问题 I've made a <sarcasm>shocking</sarcasam> discovery: Visual Studio 2015 is not C++11 compliant by default I can follow the steps I listed here for each project, or use Notepad++ or similar to do a files replace, but I do notice that the "Command Line" Properties have a checkbox: "Inherit from parent or project defaults" Is there a way to add "/Zc:rvalueCast" to my "project defaults" so everything will use it, including future projects? 回答1: Edit the microsoft.cpp.win32.user property sheet

Compile time type checking C++

╄→尐↘猪︶ㄣ 提交于 2019-12-30 10:03:47
问题 I have created a type list. I then create a class using a template passing the type list. When I call the print function of the class with a some types not specified they are casted. How can I enforce the exact type at compile time? So if I use an unlisted type I get a compiler error. Thanks. template <class T, class U> struct Typelist { typedef T Head; typedef U Tail; }; class NullType { }; typedef Typelist<int,Typelist<float,Typelist<char*,NullType> > > UsableTypes; template<class T> class

error CS0266: Cannot implicitly convert type 'object' to 'int'

限于喜欢 提交于 2019-12-30 09:55:50
问题 error CS0266: Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?) int dd= 6000; sqlCmdDefaultTime = new SqlCommand("myQuery", sqlCon); sqlDefaultTime = sqlCmdDefaultTime.ExecuteReader(); while (sqlDefaultTime.Read()) { dd= sqlDefaultTime[1]; } how can i cast 回答1: Simple cast to int : dd = (int)sqlDefaultTime[1]; 回答2: Try this... int.TryParse(sqlDefaultTime[1].ToString(), out dd); in the event that the parse is successful dd will now be a

How can an UIntPtr object be converted to IntPtr in C#?

孤者浪人 提交于 2019-12-30 08:51:15
问题 I need to convert an UIntPtr object to that of IntPtr in my C# .NET 2.0 application. How can this be accomplished? I don't suppose it's as simple as this: UIntPtr _myUIntPtr = /* Some initializer value. */ object _myObject = (object)_myUIntPtr; IntPtr _myIntPtr = (IntPtr)_myObject; 回答1: This should work on x86 and x64 IntPtr intPtr = unchecked((IntPtr)(long)(ulong)uintPtr); 回答2: This should work on 32 bit operating systems: IntPtr intPtr = (IntPtr)(int)(uint)uintPtr; That is, turn the UIntPtr

Python: unpack to unknown number of variables?

南楼画角 提交于 2019-12-30 08:20:11
问题 How could I unpack a tuple of unknown to, say, a list? I have a number of columns of data and they get split up into a tuple by some function. I want to unpack this tuple to variables but I do not know how many columns I will have. Is there any way to dynamically unpack it to as many variables as I need? Thanks for your help :) 回答1: Unpack the tuple to a list? l = list(t) 回答2: You can use the asterisk to unpack a variable length. For instance: foo, bar, *other = funct() This should put the

casting operator - const vs non-const

不羁的心 提交于 2019-12-30 08:05:13
问题 I have this code sample: class Number { int i; public: Number(int i1): i(i1) {} operator int() const {return i;} }; What are the implications of removing the const modifier from the casting operator? Does it affect auto casting, and why? 回答1: If the conversion operator is not const, you can't convert const objects: const Number n(5); int x = n; // error: cannot call non-const conversion operator 回答2: If you have a function like this: void f(const Number& n) { int n1 = n; } It will start

Is there a way to cast float as a decimal without rounding and preserving its precision?

落爺英雄遲暮 提交于 2019-12-30 07:52:06
问题 So it appears that if you CAST(field1 as decimal) field1 this will automatically add rounding. The original is defined as: field1 type:float length:8 prec:53 I need to cast it to decimal, because I need my Entity Framework layer to generate this field as decimal (instead of double). Is there a way to cast it as decimal, so that it preserves original precision, and doesn't round? I would like to avoid having to declare the precision in the cast, because: there are 100's of fields involved with

Is there a way to cast float as a decimal without rounding and preserving its precision?

岁酱吖の 提交于 2019-12-30 07:52:05
问题 So it appears that if you CAST(field1 as decimal) field1 this will automatically add rounding. The original is defined as: field1 type:float length:8 prec:53 I need to cast it to decimal, because I need my Entity Framework layer to generate this field as decimal (instead of double). Is there a way to cast it as decimal, so that it preserves original precision, and doesn't round? I would like to avoid having to declare the precision in the cast, because: there are 100's of fields involved with