What is the difference between static_cast and C style casting?
Is there any reason to prefer static_cast<> over C style casting? Are they equivalent? Is there any sort of speed difference? 7 Answers 7
Is there any reason to prefer static_cast<> over C style casting? Are they equivalent? Is there any sort of speed difference? 7 Answers 7
Using PHP, what’s the fastest way to convert a string like this: “123” to an integer? Why is that particular method the fastest? What happens if it gets unexpected input, such as “hello” or an array? 8 Answers 8
How does one handle type casting in TypeScript or Javascript? Say I have the following TypeScript code: module Symbology { export class SymbolFactory { createStyle( symbolInfo : SymbolInfo) : any { if (symbolInfo == null) { return null; } if (symbolInfo.symbolShapeType === “marker”) { // how to cast to MarkerSymbolInfo return this.createMarkerStyle((MarkerSymbolInfo) symbolInfo); } } … Read more
How do I cast an int to an enum in C++? For example: enum Test { A, B }; int a = 1; How do I convert a to type Test::A? 5 Answers 5
I know it’s possible to cast a list of items from one type to another (given that your object has a public static explicit operator method to do the casting) one at a time as follows: List<Y> ListOfY = new List<Y>(); foreach(X x in ListOfX) ListOfY.Add((Y)x); But is it not possible to cast the entire … Read more
For this code block: int num = 5; int denom = 7; double d = num / denom; the value of d is 0.0. It can be forced to work by casting: double d = ((double) num) / denom; But is there another way to get the correct double result? I don’t like casting primitives, … Read more
For example, lets say you have two classes: public class TestA {} public class TestB extends TestA{} I have a method that returns a List<TestA> and I would like to cast all the objects in that list to TestB so that I end up with a List<TestB>. 18 Answers 18
This is a silly question, but you can use this code to check if something is a particular type… if (child is IContainer) { //…. Is there a more elegant way to check for the “NOT” instance? if (!(child is IContainer)) { //A little ugly… silly, yes I know… //these don’t work 🙂 if (child … Read more
How can I convert a String such as “12.34” to a double in Java? 14 Answers 14
I have a script which reads a text file, pulls decimal numbers out of it as strings and places them into a list. So I have this list: my_list = [‘0.49’, ‘0.54’, ‘0.54’, ‘0.55’, ‘0.55’, ‘0.54’, ‘0.55’, ‘0.55’, ‘0.54’] How do I convert each of the values in the list from a string to a … Read more