Why can I get the index of the item of the array when I use string*, but
can not get the index of the array when I use any other type (such as
Int32)?
This code will compile perfectly, but if I replace String* with Int32, the
code would not compile?
The code using String* type:
#include "stdafx.h"
#using <mscorlib.dll >
using namespace System;
using namespace System::Collect ions;
int _tmain()
{
String* Items[] = { S"Dog", S"Cat", S"Elephant", S"Gerbil", S"Dog",
S"Horse", S"Pig", S"Cat" };
String* Item = S"Elephant";
int pos = Array::IndexOf( Items, Item);
Console::WriteL ine(S"Index of Item in Items is {0}", __box(pos));
return 0;
}
The code using Int32
#include "stdafx.h"
#using <mscorlib.dll >
using namespace System;
using namespace System::Collect ions;
int _tmain()
{
Int32 Items [] = {1,3,5,7,4,9,6} ;
Int32 Item = 7;
int pos = Array::IndexOf( Items, Item);
Console::WriteL ine(S"Index of Item in Items is {0}", __box(pos));
return 0;
} 1 1505
> The code using Int32 #include "stdafx.h"
#using <mscorlib.dll >
using namespace System; using namespace System::Collect ions;
int _tmain() { Int32 Items [] = {1,3,5,7,4,9,6} ; Int32 Item = 7; int pos = Array::IndexOf( Items, Item); Console::WriteL ine(S"Index of Item in Items is {0}", __box(pos));
return 0; }
Hi,
This does not compile on my machine.
However, when I change this
int pos = Array::IndexOf( Items, Item);
to this:
int pos = Array::IndexOf( Items, __box(Item));
it compiles cleanly and it also prints the correct index (3).
IndexOf expects an object reference so you have to box the int, just like
you did for the writeline.
--
Kind regards,
Bruno van Dooren br************* *********@hotma il.com
Remove only "_nos_pam" This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lawrence |
last post by:
I've waited 6 weeks for an answer to my other question and still no
luck, so let me rephrase the question. I know I can do this:
<form method="post" action="$self">
<input type="text" name="filesToDelete">
<input type="text" name="filesToDelete">
<input type="text" name="filesToDelete">
</form>
|
by: Randell D. |
last post by:
Folks,
I can program fairly comfortably in PHP and can, for the most part using
these skills and others that I've picked up over the years manage to
read/understand most code in Javascript... so I'm just asking for a few
pointers (or the full solution if you have the time) for what I want to do.
Basically, I want to write a javascript wherby I only need to pass it the
names of form fields - then my javascript will check each form field...
|
by: phancey |
last post by:
I am trying to invoke a web service method dynamically. I have created
a generic function that takes a method name, string of parameters and
calls the web method using System.Reflection:
MethodInfo mi = proxyInstance.GetType().GetMethod(methodName);
object paramsArray = (object)methodParams.ToArray(typeof(object));
object result = mi.Invoke(proxyInstance, paramsArray);
where methodParams is an array of parameters where the value...
|
by: VK |
last post by:
Whatever you wanted to know about it but always were affraid to ask.
<http://www.geocities.com/schools_ring/ArrayAndHash.html>
|
by: Venkat |
last post by:
Hi All,
Can someone tell me how do we convert a character array to string.
I know the other way.
For eg:-
String strvar = "hello";
printf("%s",strvar.c_str());
regards,
| |
by: Craig Buchanan |
last post by:
what is the fastest way to remove a value from a string array? something
like:
dim x as string() = {"A","B","C","D"}
'remove C
x.Clear(x, x.IndexOf(x, "C"), 1)
Questions:
|
by: John |
last post by:
Hi
Is there a way to create an array of strings of subscript of type index too?
Like;
x("Element A")="Value for element A"
Thanks
Regards
|
by: drako |
last post by:
Hi,
I'm a bit stumped as I am getting a "Notice: Array to String
Conversion" error when trying to do something that on the surface
should be a very simple task - create an array, and write a set of
values to them based on data submitted from POST Fields.
Code below:
$_SESSION = array();
|
by: Lonifasiko |
last post by:
Hi,
Just want to replace character at index 1 of a string with another
character. Just want to replace character at that position. I thought
Replace method would be overloaded with an index parameter with which
you can write wanted character at that position. But no, Replace
method only allows replacing one known character with another. The
problem is I don't know the character to replace, just must replace
the character at a known...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |