ctype

What is the C# equivalent of CType in VB.NET?

一曲冷凌霜 提交于 2019-11-29 13:49:53
I am trying to convert the example provided in MSDN article Creating Dynamic Data Entry User Interfaces to C#, but am stuck at the following code: CType(dq, IUIBuildingBlock).QuestionText = reader("QuestionText") How do I convert the above VB.NET statement to C#? In C#, you can specify a cast by putting the type you want to cast to in parenthesis in front of the reference variable that you want to cast ( (type)instance ). So, to cast the object ( dq ) to the type IUIBuildingBlock , you could use the following code: ((IUIBuildingBlock)dq).QuestionText = reader("QuestionText"); (Note that this

C#'s equivalent to VB.NET's DirectCast?

岁酱吖の 提交于 2019-11-28 19:05:37
Does C# have an equivalent to VB.NET's DirectCast? I am aware that it has () casts and the 'as' keyword, but those line up to CType and TryCast. To be clear, these keywords do the following; CType/() casts : If it is already the correct type, cast it, otherwise look for a type converter and invoke it. If no type converter is found, throw an InvalidCastException. TryCast/"as" keyword : If it is the correct type, cast it, otherwise return null. DirectCast : If it is the correct type, cast it, otherwise throw an InvalidCastException. After I have spelled out the above, some people have still

Which tolower in C++?

▼魔方 西西 提交于 2019-11-28 11:55:22
Given string foo , I've written answers on how to use cctype 's tolower to convert the characters to lowercase transform(cbegin(foo), cend(foo), begin(foo), static_cast<int (*)(int)>(tolower)) But I've begun to consider locale 's tolower , which could be used like this: use_facet<ctype<char>>(cout.getloc()).tolower(data(foo), next(data(foo), foo.size())); Is there a reason to prefer one of these over the other? Does their functionality differ at all? I mean other than the fact that tolower accepts and returns an int which I assume is just some antiquated C stuff? Unfortunately,both are equally

array subscript has type 'char'

旧时模样 提交于 2019-11-28 09:13:49
问题 I have the following code to read an argument from the command line. If the string is 1 character long and a digit I want to use that as the exit value. The compiler gives me a warning on the second line (array subscript has type 'char' ) This error comes from the second part after the "&&" . if (args[1] != NULL) { if ((strlen(args[1]) == 1) && isdigit(*args[1])) exit(((int) args[1][0])); else exit(0); } } Also, when I use a different compiler I get two errors on the next line (exit). builtin

What is the C# equivalent of CType in VB.NET?

做~自己de王妃 提交于 2019-11-28 07:37:35
问题 I am trying to convert the example provided in MSDN article Creating Dynamic Data Entry User Interfaces to C#, but am stuck at the following code: CType(dq, IUIBuildingBlock).QuestionText = reader("QuestionText") How do I convert the above VB.NET statement to C#? 回答1: In C#, you can specify a cast by putting the type you want to cast to in parenthesis in front of the reference variable that you want to cast ( (type)instance ). So, to cast the object ( dq ) to the type IUIBuildingBlock , you

C#'s equivalent to VB.NET's DirectCast?

三世轮回 提交于 2019-11-27 11:52:46
问题 Does C# have an equivalent to VB.NET's DirectCast? I am aware that it has () casts and the 'as' keyword, but those line up to CType and TryCast. To be clear, these keywords do the following; CType/() casts : If it is already the correct type, cast it, otherwise look for a type converter and invoke it. If no type converter is found, throw an InvalidCastException. TryCast/"as" keyword : If it is the correct type, cast it, otherwise return null. DirectCast : If it is the correct type, cast it,

Casting DataTypes with DirectCast, CType, TryCast

*爱你&永不变心* 提交于 2019-11-27 07:12:47
Ever since I moved from VB6 to VB.NET somewhere in 2005, I've been using CType to do casting from one data type to another. I do this because it is simply faster to type, used to exist in VB6 and I do not know why I have to be using DirectCast if there is apparently no difference between them. I use TryCast once in a while because I understand that sometimes casting can fail. I however cannot get the difference between CType and DirectCast. Can anyone tell me the difference in plain simple English what the difference the two (CType and DirectCast)? Adding examples of where to use what as well

Which tolower in C++?

岁酱吖の 提交于 2019-11-27 06:36:39
问题 Given string foo , I've written answers on how to use cctype 's tolower to convert the characters to lowercase transform(cbegin(foo), cend(foo), begin(foo), static_cast<int (*)(int)>(tolower)) But I've begun to consider locale 's tolower, which could be used like this: use_facet<ctype<char>>(cout.getloc()).tolower(data(foo), next(data(foo), foo.size())); Is there a reason to prefer one of these over the other? Does their functionality differ at all? I mean other than the fact that tolower

Difference between DirectCast() and CType() in VB.NET

好久不见. 提交于 2019-11-26 17:20:40
I am an experienced C/C++/C# programmer who has just gotten into VB.NET. I generally use CType (and CInt, CBool, CStr) for casts because it is fewer characters and was the first way of casting which I was exposed to, but I am aware of DirectCast and TryCast as well. Simply, are there any differences (effect of cast, performance, etc.) between DirectCast and CType? I understand the idea of TryCast. Joel Coehoorn The first thing to note is that VB.NET does not have a direct analog to C#'s (type)instance casting mechanism. I bring that up because it's useful to use that as a starting point in

Casting DataTypes with DirectCast, CType, TryCast

99封情书 提交于 2019-11-26 13:04:38
问题 Ever since I moved from VB6 to VB.NET somewhere in 2005, I\'ve been using CType to do casting from one data type to another. I do this because it is simply faster to type, used to exist in VB6 and I do not know why I have to be using DirectCast if there is apparently no difference between them. I use TryCast once in a while because I understand that sometimes casting can fail. I however cannot get the difference between CType and DirectCast. Can anyone tell me the difference in plain simple