casting

Cast one object to another

被刻印的时光 ゝ 提交于 2020-01-14 10:03:44
问题 I have got two user defined CLR objects which are identical and only differ in name, for example this code: public class Person { public string Name { get; set; } public string Address { get; set; } public string LastName { get; set; } public string ETC { get; set; } } public class PersonData { public string Name { get; set; } public string Address { get; set; } public string LastName { get; set; } public string ETC { get; set; } } I know that this can be done by creating an object from

Cast one object to another

假如想象 提交于 2020-01-14 10:03:33
问题 I have got two user defined CLR objects which are identical and only differ in name, for example this code: public class Person { public string Name { get; set; } public string Address { get; set; } public string LastName { get; set; } public string ETC { get; set; } } public class PersonData { public string Name { get; set; } public string Address { get; set; } public string LastName { get; set; } public string ETC { get; set; } } I know that this can be done by creating an object from

What happens if I cast a double to an int, but the value of the double is out of range?

限于喜欢 提交于 2020-01-14 09:59:33
问题 What happens if I cast a double to an int, but the value of the double is out of range? Lets say I do something like this? double d = double(INT_MIN) - 10000.0; int a = (int)d; What is the value of a? Is it undefined? 回答1: Precisely. Quoting from the Standard, 4.9, "The behavior is undefined if the truncated value cannot be represented in the destination type." 回答2: David Thornley answered this question completely already. However to deal with this situation in your code you should consider

How can I use a string argument to case a namespace or type?

不羁的心 提交于 2020-01-14 07:24:11
问题 I need to get some JSON output in a .NET 2.0 C# script. The goal is to use one method to output all the JSON feeds I need. All the models have the same id and name properties so I have about 15 namespaces that have the same parts here. In short: since I'm use castle I can call the function like: /public/get_place_tags.castle /public/get_place_types.castle /public/get_place_whichEver.castle Which in castle is calling each method, ie: the get_place_tags(){} but I want to not have to work where

Empty associative array SOAP type conversion

旧街凉风 提交于 2020-01-14 05:44:09
问题 I have a client server scenario where the type conversion did by the SoapClient class in PHP, cannot tell wether an empty array is associative or numeric, and so defaults to numeric. All exposed functions use basic types, no classes. An associative array such as array("something"=>123) gets converted to a map data type. However, when the same array is empty, such as array() , it gets converted to an array on the Ruby side. Type casting to object (object)array() will result in a struct data

mysql passing data to in

别说谁变了你拦得住时间么 提交于 2020-01-14 04:29:07
问题 Basically I want to fetch some data from tblvw1. Another table contains possible ids within a column which is stored as concatenated string, for example: "1|2|3|4". Next I have tried to get the result by the following query: SELECT x FROM tblname1 WHERE id IN (SELECT REPLACE(content,'|',',') FROM tblname2 WHERE dataid = y ) AS result I only get the first value, the other data wasn't fetched. I suppose that the subquery will result in this form: SELECT x FROM tblname1 WHERE id IN ('1,2,3,4')

How to convert generic primitive types in rust? [duplicate]

自闭症网瘾萝莉.ら 提交于 2020-01-14 03:55:15
问题 This question already has an answer here : How to cast generic types that I know to be integers? (1 answer) Closed 9 months ago . I would like to write something like the following in rust: pub struct Point<T> { pub x: T, pub y: T, } impl<T> Point<T> { pub fn from<U>(other: Point<U>) -> Point<T> { Point { x: other.x as T, y: other as T, } } } This is not possible: error[E0605]: non-primitive cast: `U` as `T` --> src/lib.rs:9:16 | 9 | x: other.x as T, | ^^^^^^^^^^^^ | = note: an `as`

Parse finnish date string to Date Type in VB6

ぃ、小莉子 提交于 2020-01-14 01:45:32
问题 I'm getting a Finnish date string that looks like: 29.7.2011 9:27 I'm trying to cast this string to a Date object in VB6. I've tried using the Format function but it doesn't seem to swallow the date string or I'm doing something wrong. These are some approaches I've tried: theDate = Format(dateString, "General Date") theDate = Format(dateString, "DD.MM.YYYY MM:HH") Any ideas? Thanks. 回答1: Rather than manually parsing the string yourself, which is prone to errors, and which gets messy if you

Compiler fails converting a constrained generic type

对着背影说爱祢 提交于 2020-01-13 19:24:08
问题 I have a class that has a Generic type "G" In my class model i have public class DetailElement : ElementDefinition Let's say i have a method like this public void DoSomething<G>(G generic) where G : ElementDefinition { if (generic is DetailElement) { ((DetailElement)generic).DescEN = "Hello people"; //line 1 ////// ElementDefinition element = generic; ((DetailElement)element).DescEN = "Hello again"; //line 3 ////// (generic as DetailElement).DescEN = "Howdy"; //line 5 } else { //do other

Casting generic parameter to and from integer

社会主义新天地 提交于 2020-01-13 16:20:08
问题 I want to write generic class which is intended to work with built-in types like byte and ushort . In internal computations I need to cast generic type to integer and back to generic type. I found the way to compile such code, for example: class Test<T> where T : struct, IConvertible { public static T TestFunction(T x) { int n = Convert.ToInt32(x); T result = (T)Convert.ChangeType(n, typeof(T)); return result; } } I think that using such conversions may significantly reduce performance, if