Most voted "cast" questions
Casting is a process where an object type is explicitly converted to another type, if conversion is allowed.
Learn more…76 questions
Sort by count of
-
20
votes5
answers1879
viewsWhat is the difference between an explicit cast and the operator as?
Whenever I convert an object to a specific type, I use a cast explicit, for example: private void textBox1_Leave(object sender, EventArgs e) { TextBox textBoxTemp = (TextBox)sender;…
-
19
votes2
answers8059
viewsWhat is upcasting and downcasting in the Java language?
What would be downcasting and upcasting in Java? Examples please.
-
16
votes2
answers1211
viewsWhat is the difference between using (int)variable or Convert.Toint32(variable)?
What is the difference between them? At what times is it more appropriate to use one or the other? Examples: string palavra = "10"; var numero = Convert.ToInt32(palavra); // ou (int)palavra ? string…
-
13
votes7
answers180098
viewsFormat decimal places directly in the SQL command in Firebird
I have a table ESTOQUE containing a field called QTDE, this field has 3 decimal places. What would be the command to return directly from SQL formatted with 3 houses? Because the integer values are…
-
13
votes1
answer755
viewsDifference between casting and Promotion
What is casting? What is Promotion? What is the basic difference between these Java conversion types?
-
13
votes1
answer87
viewsHow does the compiler know the difference between the type I’m using in downcasting?
The classes Felino and Ave inherit from Criatura, the values are hypothetical only to inform the difference between specialized attributes. Criatura c1 = new Felino("Preto", true); Criatura c2 = new…
-
9
votes4
answers459
viewsWhat happens when I convert int to char?
A whole has 4 bytes, whereas a char has only 1 byte. When I make that definition: int a = 1000; // 1111101000 char b = (char) a; I believe it will take only 1 byte of data, but what I want to know…
-
9
votes1
answer3505
viewsConversion to C++: What is the difference between static_cast, dynamic_cast, const_cast and reinterpret_cast?
What is the difference between casting present in the C++? There is the static_cast, dynamic_cast, const_cast and reinterpret_cast, what is the difference between these? When to use each? C++ also…
-
8
votes2
answers2353
viewsHow to get the integer value of one of the constants of an Enum?
I have an Enum (enumeration) calling Notas and need to obtain the integer corresponding to one of its constants. public enum Nota { Otimo = 5, MuitoBom = 4, Bom = 3, Regular = 2, Ruim = 1,…
-
8
votes2
answers271
views -
8
votes1
answer132
viewsIn Rust how does ampersand and asterisk work?
I came from Java recently and I’m studying Rust. Language has a totally different paradigm than I was used to, but it caught my attention. For never having messed with C or C++, sometimes I find…
-
7
votes2
answers145
viewsCAST: difference between "(String) Arg" and "String.class.cast(Arg)"
I wonder if there’s a difference between: String a = (String) arg; and the cast class: String a = String.class.cast(arg); I once heard that using the cast static class is more performatic, this is…
-
7
votes1
answer2296
viewsRounding as a result of multiplication
I have this scenario: - multiply by 2 values which will be rounded to 2 boxes for the table to be inserted. Follow the example: CREATE TABLE #TMP ( A DECIMAL(23,6), B DECIMAL(28,2) ) INSERT INTO…
-
7
votes3
answers12428
viewsWhat’s the difference between Cast and Convert?
In a Transact-SQL (Ramalho Series) book it is said: CAST AND CONVERT It implicitly converts one expression of data types to another. CAST is synonymous with CONVERT. What do you mean by CAST is…
-
6
votes2
answers350
viewsWhat is the purpose of unset as cast in PHP?
As of PHP 5, there is a way to cast in order to convert a certain value to NULL. Example: $teste = 'teste'; var_dump((unset)$teste); // NULL $outroTeste = (unset) funcao(); var_dump($outroTeste); //…
-
6
votes3
answers144
viewsType declaration in parentheses
I am porting an application done in c to C++ and found the following function statement: set_funcao(0, (double)pow((double)2, 32) ); What does the type in parentheses mean? It is the type of return…
-
5
votes1
answer1602
viewsChar vector cast for pointer
People how a cast works in a vector char for a pointer int? for example: char vetor[2]; int *p; p = (int *)&vetor; Can someone explain me this line?…
-
5
votes1
answer195
viewsWhat are the differences between the following Caps and when to use each one?
Casting [...] process where an object type is explicitly converted to another type, if conversion is allowed. Source: Stackoverflow in Portuguese Assuming the following situation: var i = 10 What…
-
5
votes2
answers211
viewsDifference in cast using "as" and "type cast"
A question arose about casting in C#, I see in many fonts using the cast in the following ways. What is the difference between one and the other, when using one way or another? public interface…
-
5
votes1
answer78
viewsType Object in PHP
I’m practicing some code in PHP when I come across this: <?php $a = (object) ["a" => "b"]; $b = (object) ["a" => "c"]; $y = $a <=> $b; echo $y; $v=[1,2,3] <=> [1,2,3]; echo $v;…
-
4
votes3
answers686
viewsHow to change a text variable to number value?
I have this segment of code, I’d like someone to help me turn the variable P (in which you take the attribute 'value' ) and turn it into number value for the sum. $(document).ready(function(e) {…
-
4
votes2
answers230
viewsDirect cast or cast functions. What is the best option?
In PHP, I realize that it is possible to do some things in countless ways. One of them that comes to my attention is the functions and functionalities related to the conversion of types. It is…
-
4
votes4
answers3012
viewsHow to convert scientific notation to full number string
What php function should I use to do this type of conversion? Convert: 1.3388383658903E+18 to: 1338838365890273563 I tried that, but it didn’t work: echo sprintf(sprintf('%%.%df', 0),…
-
4
votes2
answers196
viewsDo ( Casting ) of the return of Malloc(), Calloc() and Realloc() - C
According to the discussion Do I cast the result of malloc?, in C is not recommended or correct to cast Malloc() return. This also applies to Calloc() and Realloc functions()? Taking advantage, the…
-
3
votes1
answer631
viewsHow to cast between base and derivative classes?
I have an exercise that says I have to create a foundation. This base has two derivatives. I have to cast the derived class(1) for the derived class(2) and the derived class(2) for the base class.…
-
3
votes2
answers102
viewsIs Binary cast available in PHP?
PHP has a cast (that until then I did not know), called binary. Example of Handbook: $binary = (binary)$string; $binary = b"binary string"; According to the PHP Handbook: (Binary) - converts to…
-
3
votes1
answer1342
viewsHow to convert date to datetime?
I have the following case, I’m trying to convert the one field date for datetime using the update update tb_RHContratos set DtCadastro = cast(DtCadastro as datetime) But some of the date this does…
-
3
votes1
answer66
viewsAssign/Print values to void * in a structure
#include <stdio.h> typedef struct elem{ void * d; }Elem; main(){ Elem *p; Elem e; double pi = 3.14; e.d = π p->d = π printf("%f\n",p->d); printf("%f\n",e.d); } When I do…
-
3
votes1
answer107
views -
3
votes2
answers307
viewsC Cast vs C++ Cast
What’s the difference between using the C cast: float t = 5.0f; int v = (int)t; For the cast of C++: float t = 5.0f; int v = static_cast<int>(t);…
-
3
votes1
answer59
viewsHow to interpret this line? (struct list*)0)
while (variavel != (struct lista*)0) { ... } How to interpret (struct lista*)0)? What does that mean?
-
3
votes1
answer53
viewsWhat’s wrong with using reinterpret_cast on C++?
I know what to use reinterpret_cast may cause indefinite behavior, but I still don’t understand why (I know it has something to do with the life cycle of the object and alignment of memory). I would…
-
3
votes3
answers77
viewsHow can I access a subclass method through a superclass-like object
Having an ABC super class public class ABC { int x = 0; public int getABC() { return x; } } public class XYZ extends ABC { int y = 0; public int getXYZ() { return y; } } Instantiating an ABC object…
-
3
votes2
answers164
viewsUpcasting and subsequent downcasting allows you to access the attribute of the original type?
When I make a upcasting, object 1 will be converted to its supertype and an object 2 is created When object 1 is instantiated before doing the upcasting, has attributes that do not exist in the…
-
2
votes1
answer65
viewsDifference between "Object(meuobjeto)" and "(meuobjeto as Object)"?
I wish I knew the difference between using Object(meuobjeto) and (meuobjeto as Object) based on the code below: var mc:MovieClip = new MovieClip(); //Um objeto MovieClip trace(mc as String); //null…
-
2
votes1
answer47
viewsHow to turn a cv::Mat into ipcMatrix<ipcRGB>?
Does anyone know if there’s an easy way to turn a cv::Mat in ipcMatrix<ipcRGB>?…
-
2
votes1
answer46
viewsArraylist: Is that right or is there a better way to do it?
I know a bit of java, but now I’m venturing into C#, but a question came up here: In java we instantiated an Arraylist like this: ArrayList<Tipo> nomeArray = new ArrayList<>(); We…
-
2
votes2
answers697
viewsClasscastexception error when trying to cast between classes
I have the problem to perform a "Cast" in a class, when using the inherited class method of the following error: "entity. Aula cannot be cast to tableview.Aulatv" Here gives the exception described…
-
2
votes1
answer134
viewsDifference in Java casting
What is the difference between the 2 codes below? first int x = 10; float i = (float) x; 2nd int x = 10; float i = Float.parseFloat(x);…
-
2
votes1
answer77
viewsWhy does this work? pointer = (struct a *)&b;
struct a { int a; int b; }; struct b { int a; int b; }; struct a *ponteiroa; struct b b; b.b = 20; ponteiroa = &b; //Isto não dá certo ponteiroa = (struct a *)&b; Why is this (struct a…
-
2
votes1
answer32
viewsCast in MYSQL X Performance
I’m trying to improve my Sqls in Mysql and PHP, in the analysis I ended up coming to a CAST function is increasing by at least 5X the search time as follows below: CUSTOMERS table where the DATACAD…
-
1
votes2
answers4866
viewsJava.lang.String cannot be cast to error , when capturing data in Jcomobox to save
I have the event button saved, when I click to save, the following appears : Java.lang.String cannot be cast to org.nomedopacote.modelo.Funcionario cbNomeUsuario - It’s Jcomobox’s name that they’re…
-
1
votes1
answer1667
viewsString Cast for int Hibernate
Does anyone know how to cast a String for int within the query in this query, the variable "searchString"? @Query("SELECT s FROM StoreOrder s INNER JOIN s.user u WHERE lower(u.fullname) LIKE…
-
1
votes1
answer112
viewsHow to simulate a cast of a class in PHP (other than stdClass)?
It seems to me that in java there is a way to make Casts to make a particular object instance of another. Example: MyClass variable = (MyClass) my_other_class; In php it is possible to make type…
-
1
votes1
answer146
viewsStruct pointer cast doubt
I can’t understand the meaning of this cast: the function will execute and returns a type type_t, which is a typedef for void*. Then is made a cast for header_t*, which is a struct, but I can’t…
-
1
votes0
answers92
viewsGet XML properties answered from web services server
I am wanting to capture the values of XML properties answered by the server. public ArrayList<Carga> smbcRequest(smbc smbc) { //instanciando variaveis PropertyInfo req = new PropertyInfo();…
-
1
votes1
answer97
viewsMultiple cast in java
I’m having a hard time doing an exercise because I don’t know how to solve this kind of casting: The class D is the superclass. The class C is the subclass. D d = (D) (C) new D(); I’d be grateful if…
-
1
votes1
answer211
viewsSelect with cast(Numeric as decimal) works, but view creation does not
Good morning to all! I currently work with postgresql and am doing a database migration, and need to create a view of my old database tables. Well, I need the numerical columns to be rounded 15.3…
-
1
votes1
answer364
viewsCast webview android studio
I’m making an app for my website, which is just a webview, can anyone tell me if it’s possible to put to broadcast on Smart TV? if yes, can you tell me where to take a study about? or even help me…
-
1
votes1
answer91
viewsInt field as string
I’m working on a code for a college job, but I’m having problems, although the "home" is set to INT, netbeans continues to present: "incompatible types: String cannot be converted to int" below…