casting Questions

21

I have a class Animal, and its subclass Dog. I often find myself coding the following lines: if (animal is Dog) { Dog dog = animal as Dog; dog.Name; ... } For the variable Animal animal;. ...
Edana asked 18/8, 2011 at 19:57

3

Solved

It seems if it's just a variable, I can conditionally cast like this. Animal animal = Dog(); if (animal is Dog) { animal.bark(); // animal is of type Dog here } But if it's a property on a clas...
Banwell asked 28/5, 2019 at 1:41

5

Solved

I see this Array.ConvertAll method, but it requires a Converter as an argument. I don't see why I need a converter, when I've already defined an implicit one in my class: public static implicit o...
Shaeffer asked 14/1, 2010 at 22:47

9

Solved

I have a small table and a certain field contains the type "character varying". I'm trying to change it to "Integer" but it gives an error that casting is not possible. Is there a way around this ...
Dionisio asked 1/11, 2012 at 3:33

9

Solved

I have a generic class which saves value for the specified type T. The value can be an int, uint, double or float. Now I want to get the bytes of the value to encode it into an specific protocol. T...
Raisaraise asked 11/4, 2013 at 21:4

2

Solved

Is there an elegant way to cast a bigger datatype to a smaller one without causing the result to overflow? E.g. casting 260 to uint8_t should result in 255 instead of 4. A possible solution would b...
Fitful asked 1/4, 2022 at 9:49

3

Solved

I'm working with indexeddb and typescript. My issue is that TS doesn't seem to be able handle the event.target.result property. Case in point: request.onsuccess = (event) => { namespace.db = e...
Denude asked 15/12, 2014 at 18:22

8

Solved

I want to extract just the date part from a timestamp in PostgreSQL. I need it to be a postgresql DATE type so I can insert it into another table that expects a DATE value. For example, if I have...
Deauville asked 26/5, 2011 at 2:32

6

Solved

how can I convert any object of my own class convert into pointer to void? MyClass obj; (void*)obj; // Fail
Enterpriser asked 30/6, 2011 at 11:47

13

Solved

I am trying to convert my string formatted value to date type with format dd/MM/yyyy. this.Text="22/11/2009"; DateTime date = DateTime.Parse(this.Text); What is the problem ? It has a second ov...
Wittenberg asked 3/2, 2010 at 15:24

8

Solved

public class Animal { public void eat() {} } public class Dog extends Animal { public void eat() {} public void main(String[] args) { Animal animal = new Animal(); Dog dog = (Dog) animal; }...
Mythologize asked 1/2, 2011 at 13:11

7

Solved

Suppose I have two classes deriving from a third abstract class: public abstract class Parent{ public Parent(){ } } public class ChildA extends Parent { public ChildA { } } public class Chil...
Triangular asked 27/12, 2011 at 22:32

5

Solved

I have a misunderstanding about typecasting in Java language. The problem is ClassCastException. For example, in this code, assuming Animal is the parent class of the Dog class, Animal animal = ne...
Beautify asked 7/8, 2014 at 22:4

2

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 Cur...
Paries asked 9/8, 2011 at 3:17

1

In building libraries for controlling hardware on embedded microprocessors, a common task is manipulating bits at specific memory locations for controlling hardware features. In AVR processors, Atm...
Torsibility asked 2/2, 2019 at 0:33

14

Solved

I'm getting in an int with a 6 digit value. I want to display it as a String with a decimal point (.) at 2 digits from the end of int. I wanted to use a float but was suggested to use String for a ...
Manganous asked 4/5, 2011 at 13:42

15

Solved

Is there a way to convert an integer to a string in PHP?
Merritt asked 23/6, 2009 at 22:37

5

When I declare a char * to a fixed string and reuse the pointer to point to another string /* initial declaration */ char *src = "abcdefghijklmnop"; ..... /* I get the "warning: assignment makes ...
Cauterant asked 25/2, 2011 at 20:25

4

Solved

I'd expect this code to throw a ClassCastException: public class Generics { public static void main(String[] args) { method(Integer.class); } public static <T> T method(Class<T> t...
Fanchie asked 19/11, 2010 at 12:41

1

Solved

According to [expr.cast]/4, a C-style cast tries the following casts in order: const_cast static_cast static_cast followed by const_cast reinterpret_cast reinterpret_cast followed by const_cast ...
Recriminate asked 30/3, 2018 at 21:47

3

Solved

I am new to programming and am currently studying about address typecasting. I don't seem to understand why I am getting this : *** stack smashing detected ***: terminated Aborted (core dumped) whe...
Doublure asked 22/2, 2022 at 11:34

2

Solved

I have a problem to cast or convert ExpandoObject to Object that is specific class in C# project. Class of Object: public class PlayerData { public string Id {get; set;} public string Phone { get...
Pteridology asked 28/12, 2020 at 10:0

2

Solved

I have a pointer T * pValues that I would like to view as a T (&values)[N] In this SO answer https://stackoverflow.com/a/2634994/239916, the proposed way of doing this is T (&values)[N] = *...
Osculate asked 23/1, 2014 at 19:3

2

Solved

I am trying to implement a neural net in PyTorch but it doesn't seem to work. The problem seems to be in the training loop. I've spend several hours into this but can't get it right. Please help, t...
Barney asked 9/5, 2021 at 9:53

4

I'd like to access form elements via myForm.elements, and then access each element by it's name, for example, myForm.elements.month. Typescript doesn't like this b/c it doesn't know that form.eleme...
Lafreniere asked 27/4, 2015 at 22:35

© 2022 - 2024 — McMap. All rights reserved.