|
Hi all,
i am retuting an string array..but the errror is..
Cannot implicitly convert type 'string[]' to 'string'
Please help me, with a sample to return a basic array return
prashanth,
s/w Engineer,
Syfnosys.
|
|
|
|
|
The error is telling you that you are trying to force a string array into a string. I assume that you are trying to return a string array, in which case the following will suffice:
public string[] GetValues()
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi i sorry, if any big blunders
i am very new to this kind of programming plese help me
actually i have collected some values from xml file and i need to disply them
so
i wrote
public string[] GetLaserProp(string laserid, string parentnode1, string childnode1)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(@"E:\Dropdown_XML\laserProp.xml");
string[] str = new string[5];
// XmlNodeList xmlnodelst = xmldoc.GetElementsByTagName("laser");
XmlNodeList xmlnodelst = xmldoc.GetElementsByTagName(parentnode1);
//return xmlnodelst;
//foreach (XmlNode.parentnode in xmlnodelst)
foreach (XmlNode parentnode in xmlnodelst)
{
//MessageBox.Show(parentnode.Attributes.Item(0).Value);
if (parentnode.Attributes.Item(0).Value == laserid)
{
xmldoc.LoadXml(parentnode.InnerXml);
//XmlNodeList xmlchildnodelst=xmldoc.GetElementsByTagName("gauge");
XmlNodeList xmlchildnodelst = xmldoc.GetElementsByTagName(childnode1);
// cmbChildLaser.Items.Clear();
foreach (XmlNode childnode in xmlchildnodelst)
{
for (int i = 0; i < childnode.ChildNodes.Count; i++)
{
//cmbChildLaser.Items.Add(childnode.ChildNodes.Item(i).Attributes.Item(0).Value);
for (int j = 0; j < childnode.ChildNodes.Item(i).Attributes.Count; j++)
{
// MessageBox.Show(
str[j]= childnode.ChildNodes.Item(i).Attributes.Item(j).Value;
//cmbChildLaser.Items.Add(xmlnodelst1.Item(ii).ChildNodes.Item(0).InnerText);
return str;
}
}
}
}
}
//return (Student []) students.ToArray();}
return str;
prashanth,
s/w Engineer,
Syfnosys.
|
|
|
|
|
Gosh! That code is very difficult to read because of all the commented out lines. This can be quite confusing.
Here is a cleaner version of the code you've supplied:
public string[] GetLaserProp(string laserid, string parentnode1, string childnode1)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(@"E:\Dropdown_XML\laserProp.xml");
string[] str = new string[5];
XmlNodeList xmlnodelst = xmldoc.GetElementsByTagName(parentnode1);
foreach (XmlNode parentnode in xmlnodelst)
{
if (parentnode.Attributes.Item(0).Value == laserid)
{
xmldoc.LoadXml(parentnode.InnerXml);
XmlNodeList xmlchildnodelst = xmldoc.GetElementsByTagName(childnode1);
foreach (XmlNode childnode in xmlchildnodelst)
{
for (int i = 0; i < childnode.ChildNodes.Count; i++)
{
for (int j = 0; j < childnode.ChildNodes.Item(i).Attributes.Count; j++)
{
str[j]= childnode.ChildNodes.Item(i).Attributes.Item(j).Value;
return str;
}
}
}
}
}
return str;
}
Which line contained the error, because I cannot see anything here that would cause the error. Perhaps, as Pete suggested, the error is in the caller.
|
|
|
|
|
Colin Angus Mackay wrote: Which line contained the error, because I cannot see anything here that would cause the error.
Me neither
Colin Angus Mackay wrote: Perhaps, as Pete suggested, the error is in the caller.
agreed
modified 12-Sep-18 21:01pm.
|
|
|
|
|
You force your array to have a size of 5. What happens if you have more than 5 matches?
If you're using .NET 2, you would be better using this:
public List<string> GetLaserProp(string laserid, string parentnode1, string childnode1)
{
List<string> list = new List<string>();
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(@"E:\Dropdown_XML\laserProp.xml");
XmlNodeList xmlnodelst = xmldoc.GetElementsByTagName(parentnode1);
foreach (XmlNode parentnode in xmlnodelst)
{
if (parentnode.Attributes.Item(0).Value == laserid)
{
xmldoc.LoadXml(parentnode.InnerXml);
XmlNodeList xmlchildnodelst = xmldoc.GetElementsByTagName(childnode1);
foreach (XmlNode childnode in xmlchildnodelst)
{
for (int i = 0; i < childnode.ChildNodes.Count; i++)
{
for (int j = 0; j < childnode.ChildNodes.Item(i).Attributes.Count; j++)
{
list.Add(childnode.ChildNodes.Item(i).Attributes.Item(j).Value);
}
}
}
}
}
return list;
}
-- modified at 10:05 Wednesday 7th March, 2007
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Why not using a List<string> ?
---
single minded; short sighted; long gone;
|
|
|
|
|
I did, but the formatting got stripped out. (Show's I should preview my posts). I'll fix it ASAP.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi
I am developing a windows application in which it contains a grid. on double clicking a row on the Grid it shows all the details about that row in a new form.
If i double click the same row or other row it opens the details of respective row again in a same form.
For this i followed one logic. I take a global variable (public boolean X= false) and i am setting it true when user double clicks a row. I am resetting it in the child form. Here the value is not resetting.
What i want is Is there any mechanism or statements of code to preventing the form from openning more than one form at a time.
Please Help me.
Thanks in Advance.
Ramu Medida.
|
|
|
|
|
Open the form in modal mode. Form1.ShowDialog.
This will keep it from opening another form until this one has been closed.
Make sure you call Form1.Dispose after ShowDialog because the memory is not released when using ShowDialog as with other Show methods.
|
|
|
|
|
Instead of re-creating the child form everytime you double click on the parent form, re-use a single child form, showing or hiding it as appropriate. Before you show the form, you can use a DataView on the child form to show the data you're insterested in.
|
|
|
|
|
i would use a singleton pattern for the form
roughly:
public class MyForm:Form<br />
{<br />
private static MyForm _formInstance;<br />
private MyForm()<br />
{<br />
}<br />
public static MyForm GetFormInstance()<br />
{<br />
if (_formInstance == null) _formInstance = new MyForm();<br />
return _formInstance;<br />
}<br />
}
Hope this helps
Russell
-- modified at 4:15 Thursday 8th March, 2007
|
|
|
|
|
Thank You Very Much.
It is working for me.
Once Again Thank You.
Ramu Medida.
|
|
|
|
|
I would like to ask if it is possible to check the ports of a computer are being scanned?
I am writing a program to send out file and I would like to add a function to it by checking if that machine is being scanned by others.
May I know if C# can archieve this? Are there any samples?
Thank you very much.
|
|
|
|
|
A port scan works by attempting to open a port on a specific machine. Usually checks like this are done in the firewall(just disable port scanning). If you really want to check to see if your are being scanned the most likely place to look is in the WinSocks library functions available from Windows. They may offer such a hook. Other than that I know of no method to listen for port activity in Windows without actually creating a socket listener.
File Not Found
|
|
|
|
|
Hello,
Is there any way to restrict the DateTimePicker to display only the monthe and the year.
Dad
|
|
|
|
|
Yes, use an appropriate custom format; I use:
<br />
this.dtpDateTime.Format = System.Windows.Forms.DateTimePickerFormat.Custom ;<br />
this.dtpDateTime.CustomFormat = "yyyy-MM-dd HH:mm:ss" ;<br />
These can be set in the designer.
--| "Every tool is a hammer." |--
|
|
|
|
|
try setting the Format property to custom and the CustomFormat proprty to "MM/yyyy" .
Hope this helps.
V.
I found a living worth working for, but haven't found work worth living for.
|
|
|
|
|
Hai friends,
i am final ME student.
i need correct implementation of multiple description coding technique in c#.
Otherwise how to use this technique
Please help because i am doing project in MANET video communication
Narayani
|
|
|
|
|
wrote: i need correct implementation of multiple description coding technique in c#.
I did a quick google on that expression and all I found was a number of academic papers published within the last 5 years. You might get a positive response here, but you may have a better chance of receiving an answer by posting this question on an appropriate academic forum.
|
|
|
|
|
Hello all!
Iam writing a tool that will develope elearning content for the web. This tool has to be run as a clientside application. After working on web applications for so long iam really unsure about what is the best language / development tools to develope such an application in.
Ive looked into developing it in c# as this is a language iam comfortable with but iam sure unsure on the whole about developing clientside applications with .net technologies and would like to know peoples considerations on doing this.
One consideration ive come accross is redistributing the .net framework for people who do not have it already installed. Ive read this can be as little as 22mb. Another thing iam concerned about is performance. I would like the application to run as fast as any other desktop tool, but obviously there is the concern that .net languages compile to CLR so there is a processing overhead there.
Another thing is that this application will have some pretty intense GUI requirements and iam unsure if c# is the right language for doing this kind of work.
Does anyone have any council to offer on this.....please?
|
|
|
|
|
Mr Withers wrote: One consideration ive come accross is redistributing the .net framework for people who do not have it already installed. Ive read this can be as little as 22mb.
Is that really a concern. If you are distributing by CD then that is only about 4% of the disc. If you are distributing over the web 22Mb is not a lot these days.
Mr Withers wrote: Another thing iam concerned about is performance. I would like the application to run as fast as any other desktop tool, but obviously there is the concern that .net languages compile to CLR so there is a processing overhead there.
A one time overhead to compile to the most efficient code for the processor on the machine. You can distribute your app to 5 different machines and the JIT compiler will compile each differently to take advantage of the various hardware. You couldn't do that with a non-JITed language.
Mr Withers wrote: Another thing is that this application will have some pretty intense GUI requirements and iam unsure if c# is the right language for doing this kind of work.
Have you looked at WPF (Windows Presentation Foundation) in .NET 3.0?
|
|
|
|
|
I do agree that 22mb isnt alot - i guess i was kinda putting in as more of a example consideration lol, I had no idea that the overhead was a onetime only - I was thinking back to java and JVM where it run horribly slow at times. This does sound very promising.
I assumed avalon (WPF) was longhorn/vista only, one of my requirements is that it runs on XP as well (I should have mentioned this). Looking past the visual studio toolbox ill probably have to look at GDI or whatever its become now unless iam mistaken?
|
|
|
|
|
Mr Withers wrote: I assumed avalon (WPF) was longhorn/vista only, one of my requirements is that it runs on XP as well
WPF will run on XP
Mr Withers wrote: Looking past the visual studio toolbox ill probably have to look at GDI or whatever its become now unless iam mistaken?
From what I understand GDI has effectively been deprecated with the release of Vista. So long as you don't need to support Windows 2000 or earlier then I would say WPF is the way to go now.
|
|
|
|
|
Thanks this sounds like the ways forwards, ill start doing some research into these things and get to grips with them.
A bit off topic - but I have to write a video hook that ties in with this app so I can grab video sequences of the user interacting with the desktop / applications.
Just wondering if this kind of thing is possible with c# or will it be a bit of a hack?
|
|
|
|