casting

C# Casting to a decimal

瘦欲@ 提交于 2020-01-02 01:06:10
问题 What, if any, is the difference between? decimal d = (decimal) myDouble; decimal d = new decimal(myDouble); decimal d = Convert.ToDecimal(myDouble); 回答1: There is no difference. If you look at the source: In Decimal: public static explicit operator decimal(double value) { return new decimal(value); } In Convert: public static decimal ToDecimal(float value) { return (decimal) value; } So in the end they all call new decimal(double) . 回答2: They all achieve the same results. However, here's a

Want to cast unique values into first/second/third variables

扶醉桌前 提交于 2020-01-01 19:18:11
问题 I have a sample of a dataset that needs to be cast into a wide format, but I have a particular issue that I haven't seen addressed on StackOveflow yet. The column that I'd like to use to make a long dataset has unique values for every single row, but I want to create a new dataset so that are n variables for n attributes for each idvar. I need to convert this: state sector attribute_value alabama 1 a alabama 1 b alabama 1 c alabama 1 d alabama 1 e alabama 1 f alabama 1 g alabama 1 h alaska 1

ctypes: Cast string to function?

孤街醉人 提交于 2020-01-01 16:24:31
问题 I was reading the article Tips for Evading Anti-Virus During Pen Testing and was surprised by given Python program: from ctypes import * shellcode = '\xfc\xe8\x89\x00\x00....' memorywithshell = create_string_buffer(shellcode, len(shellcode)) shell = cast(memorywithshell, CFUNCTYPE(c_void_p)) shell() The shellcode is shortened. Can someone explain what is going on? I'm familiar with both Python and C, I've tried read on the ctypes module, but there are two main questions left: What is stored

Convert or Cast a Simple Object to Object of another class

≡放荡痞女 提交于 2020-01-01 14:34:33
问题 I've an object pObject Object pObject = someRpcCall(); I don't know the type of pObject What i know is System.out.println(pObject.toString()) outputs {partner_shipping_id=12, partner_order_id=11, user_id=1, partner_invoice_id=13, pricelist_id=1, fiscal_position=false, payment_term=false} How can I convert this pObject to object of the following class import android.os.Parcel; import android.os.Parcelable; public class Customer implements Parcelable { private int id; private String name = "";

In C#, can you cast one generic type to another who's T parameter is a subclass of the first's T?

二次信任 提交于 2020-01-01 14:19:41
问题 I'm running into an issue where I have one generic that I'm trying to cast to another where the second's generic T parameter is a subclass of the one used in the first. Here's my code, simplified for understanding... public partial class HierarchicalItem { public ObservableHierarchicalCollection<HierarchicalItem> ContainingCollection{ get; private set; } public HierarchicalItem Parent{ get{ return (ContainingCollection != null) ? ContainingCollection.Owner : null; }} } public partial class

Is it possible to cast a DECIMAL to DOUBLE in MySQL?

a 夏天 提交于 2020-01-01 10:53:08
问题 I know all the numerical implications, that is, the possible rounding issues inherent to floating point formats, but in my case I have DECIMAL columns in MySQL that I want to convert to DOUBLE straight in the MySQL query rather than down stream. Could anyone help? 回答1: SELECT my_decimal_field + 0E0 FROM my_table 回答2: It seems not possible to cast it to DOUBLE which brings problems if you do calculations and for example want to ROUND() a DECIMAL 12,2 in the third digit. Using ROUND(foo * bar,2

Casting to a Class which is determined at run-time

╄→尐↘猪︶ㄣ 提交于 2020-01-01 10:49:49
问题 I have a method fetchObjects(String) that is expected to return an array of Contract business objects. The className parameter tells me what kind of business objects I should return (of course this doesn't make sense in this construed case because I already said I will return Contract s, but it's basically the situation I have in my real scenario). So I get the set of entries from somewhere and load the class of the collection's entries (the type of which is specified by className ). Now I

Difference between casting ifstream to bool and using ifstream::is_open()

此生再无相见时 提交于 2020-01-01 10:04:13
问题 Maybe a dummy question, but I need a clear answer to it. Is there any difference at all in the return of any of those functions int FileExists(const std::string& filename) { ifstream file(filename.c_str()); return !!file; } int FileExists(const std::string& filename) { ifstream file(filename.c_str()); return file.is_open(); } So in other words, my question is: does casting the fstream to bool give exactly the same result as fstream::is_open()? 回答1: No. is_open checks only whether there is an

Ansi SQL type casting

帅比萌擦擦* 提交于 2020-01-01 09:39:54
问题 Is it allowed to cast types in ANSI SQL like in postgres for example: SELECT SUM( CAST(qnty AS int) - CAST(reserve AS int) ) AS sum ... qnty and reserve are character columns. 回答1: The CAST expression was added in SQL-92. You can see it for example in this draft. 来源: https://stackoverflow.com/questions/1530003/ansi-sql-type-casting

Cast string.Empty to (generic) T in C#?

▼魔方 西西 提交于 2020-01-01 09:22:15
问题 I have a utility method which returns a strongly typed value from an old .INI configuration type file, with the signature internal static T GetIniSetting<T>(string config, string key, T defVal = default(T)) I want strings to be special, in that I would like the default value for defaultValue to be string.Empty , not default(string) (i.e. null), in the case when the coder hasn't specified a default value. if (cantFindValueInIniFile == true) { if ((typeof(T) == typeof(string)) && (defaultValue