Casting from 'System.Int16' to type 'System.Int32'

Advertisements I encountered an error saying that "Unable to cast object of type ‘System.Int16‘ to type ‘System.Int32‘." Isn’t it too unlogical? How come? When I try the following on immediate windows, the output as such that reader.GetInt16(mycolumn_ordinal_value) 999 reader.GetInt32(mycolumn_ordinal_value) Exception thrown: ‘System.InvalidCastException’ in Microsoft.Data.SqlClient.dll At DB level (sqlserver), it is defined as mycolumn smallint. When… Read More Casting from 'System.Int16' to type 'System.Int32'

Are there good reason to accept float but not int in a function in Python?

Advertisements In a big library, I had a ‘bug’ because a function which accept only float but not int def foo(penalty: float): if not isinstance(penalty, float): raise ValueError(f"`penalty` has to be a float, but is {penalty}") # some instruction I would like to open a PR with the following : def foo(penalty: int | float):… Read More Are there good reason to accept float but not int in a function in Python?

Is type conversion having a covariance error?

Advertisements I’m learning how to build a compiler through a YouTube video, and there’s a part where there’s a type conversion error, in the locals.Add(parameter, value); section there’s this error from Visual Studio for Mac, saying that the variable parameter with the type ParameterSymbol can’t be converted to VariableSymbol. Argument 1: cannot convert from ‘Compiler.SupportedExpressions.Symbols.ParameterSymbol’… Read More Is type conversion having a covariance error?

C# type casting isn't checked when a function takes a dynamic object as input parameter

Advertisements I have a function that takes in a dynamic type object. The function does work to parse that object then returns back some information about what it parsed. For some weird reason when I take the returned object and store it into another variable, that new variable doesn’t check to see that the object… Read More C# type casting isn't checked when a function takes a dynamic object as input parameter

SQL Convert Varchar to Date

Advertisements I have a query that grabs a yyyy-MM-dd format from a large storage field by substringing, so the value is automatically a varchar. An example of the entire record’s contents is below: EmployeeName$Test User Email$test@test.com ADUsername$tuser TermDate$2023-07-13 EmployeeNumber$12345 Department$Tech The following SQL query works and returns all data correctly, where TermDateString is never null… Read More SQL Convert Varchar to Date