casting

Which is faster between (string)$value and “$value” when casting to a string

放肆的年华 提交于 2019-12-12 20:17:33
问题 In PHP, assuming $value = 12345; (an integer), which is faster when casting $value from an integer to a string; $value = (string)$value; or $value = "$value"; This is a kind of performance measure question and specifically for this case. Thanks for your help! 回答1: Your question is really about the efficacy of the php interpreter, and how it converts php code (the one you write) to php bytecode (the one that runs and may actually consume time and resources). If i take p01ymath's experiment,

SQL, CONVERT, CAST Data Type?

折月煮酒 提交于 2019-12-12 19:40:37
问题 I am not sure how to use either CAST or CONVERT in this script. SQL says: Conversion failed when converting the varchar value 'Amazing' to data type int. Can someone please tell me how to do this? USE AdventureWorks2012 GO DECLARE @Number01 AS INT DECLARE @Number02 AS INT DECLARE @Number03 AS INT DECLARE @Number04 AS INT DECLARE @Number05 AS INT DECLARE @Number06 AS INT DECLARE @Number07 AS INT DECLARE @Text01 AS VARCHAR (15) SET @Number01 = 150 SET @Number02 = 200 SET @Number03 = 350 SET

Changing the type of primitive arrays in Java

送分小仙女□ 提交于 2019-12-12 19:23:06
问题 I have a numeric program in Java that does a lot of operations on primitive arrays. I use primitive arrays ( double[] / float[] / int[] ) because they are much more memory and time-efficient than dealing with arrays of pointers to values (e.g. ArrayList<Float> ). Now, I want to be able to change my primitive type, eg. from double to float, based on some parameter to my program. But since primitive can not be used as generics, I can't for the life of me figure out how. Is there any way, or is

Difference between type cast and 'as' cast [duplicate]

两盒软妹~` 提交于 2019-12-12 19:19:39
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Casting vs using the ‘as’ keyword in the CLR I know there are a lot of questions about casts but I don't know the specific names of these two casts so I'm not sure where to look. What are the differences between the two casts below? TreeNode treeNode = (TreeNode)sender; // first cast TreeNode treeNode = (sender as TreeNode); //second cast 回答1: The first type of cast is called an "explicit cast" and the second

Integer conversion (explicit and implicit casting)

℡╲_俬逩灬. 提交于 2019-12-12 19:17:21
问题 I looked around and only found more complicated posts involving pointers. I'm learning C, and just wanted to confirm my understanding of a few examples. (These examples assume int and short int sizes of 32 and 16 bits, respectively.) Initial code: int int1 = 70000; int int2; short int shortInt1 = -70; short int shortInt2, shortInt3; And some sample conversions: shortInt2 = int1 / shortInt1; My understanding: i. Division is conducted (70000 / -70), yielding a value of -1000 ii. Because int has

Casting to generic type fails in c#

我与影子孤独终老i 提交于 2019-12-12 18:44:18
问题 I'd wish to save some coding by being able to create a dynamic GetControl method. My ideas is something like this private T GetControl<T>(ASPxGridView control, string element) { var returnedElement = (T)control.FindEditFormTemplateControl(element); return returnedElement; } Which I call with var myElement = GetControl<ASPxTextBox>(myGridView, "UserId"); But, this fails miserably: Cannot convert type 'System.Web.UI.Control' to 'T' Any advices? 回答1: Try adding a generic constraint: private T

TypeScript error on implicit type conversion

戏子无情 提交于 2019-12-12 18:27:43
问题 Is there a way to make TypeScript throw an error on an implicit type conversion? Seems to me like all the implicit type conversions in JavaScript are one of the larger sources of bugs in the language, so I'd like a way for something like the following code: let h = (n: number): number => { let f = () => 0 return -f } to let me know it will be implicitly converting the function type to a number via the - operator, and thus always returning NaN . 回答1: TypeScript allows this because it is valid

C++ dynamic_cast vs storing object type in a static enum?

偶尔善良 提交于 2019-12-12 18:27:24
问题 I am developing a big hierarchy of classes for a framework that will require quite a lot of type casting when it gets done. My question is, how stupid of an idea is to put in a static member that uses an enum to store all the object types in the hierarchy. Having the member static for every class will not increase the instanced object sizes, and will give a (potentially) faster way to determined the type of an object during runtime than dynamic_cast. At least that's the basic idea. How

Prevent mysql casting string to int in where clause

不羁岁月 提交于 2019-12-12 18:23:54
问题 I'm trying to prevent mysql from casting a string to an int in a where clause. The following query returns the correct row for the order SELECT delivery_name FROM orders WHERE orders_id = '985225' The following query also returns the same row as it is casting my string to an int, but I'd like to prevent it from returning the row at all (ie, not cast the string given to an int and effectively say, this cannot accurately be cast to an int so don't). SELECT delivery_name FROM orders WHERE orders

WPF Cursor casting problem

☆樱花仙子☆ 提交于 2019-12-12 18:09:30
问题 I have a System.Windows.Forms.Cursor with me and wanted to assign it to a WPF's image.Cursor property which happens to be of System.Windows.Input.Cursor type. The constraint here is, the former Cursor type is returned by our Framework and i can in no way modify it. Is there any way of casting the former to latter? 回答1: This did the trick for me: SafeFileHandle panHandle = new SafeFileHandle(System.Windows.Forms.Cursors.PanNorth.Handle, false); this.Cursor = System.Windows.Interop