|
Ok I solved the problem...
For some reason it didnt like the fact that I had the return activeRoom; in the follow position
foreach (cRoom room in roomList)
{
if (room.RID == RID)
{
activeRoom = room;
return activeRoom;
}
}
So I moved it here
foreach (cRoom room in roomList)
{
if (room.RID == RID)
{
activeRoom = room;
}
}
return activeRoom;
and it worked fine
I guess I cant have a return value in a foreach loop
Thanks for your help. =)
|
|
|
|
|
jblouir wrote: I guess I cant have a return value in a foreach loop
You can, although it's good form to only have one return, at the end of a method.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
jblouir wrote: im only returning the cRoom object
Not always, that's what the error message is saying.
Look at the logic in the method. If activeRoom.NORTH is non-zero but not found in the list, the method doesn't return anything.
---
single minded; short sighted; long gone;
|
|
|
|
|
If you declare a method that returns a value, you must make sure that all places where you may exit the function will return a value of that type. Example:
public int MyFunc()
{
if (errorcondition)
{
return 2;
}
else
{
...
}
return 0;
}
}
|
|
|
|
|
I am trying to use the same class to populate the second list in my second class, but the list will have the last set of values. The only way that it work if I instantiate multiple classes, please help, why I can not use only instantiating my classes once . Here are the codes
<b><pre>First file</pre></b>
<code>
using System;
using System.Collections.Generic;
using System.Text;
namespace xpop
{
class Program
{
static void Main(string[] args)
{
_xobj xobj = new _xobj();
popxmlobj(xobj);
}
// Does work but have to instatiate the calss object twice need to re- use the calss object
static void popxmlobj1(_xobj xobj)
{
_AllValue aValue1 = new _AllValue();
aValue1.valueName = "VAL1Name";
aValue1.Values.Add("Val1");
xobj.fieldName = "FieldName1";
xobj.fieldValues.Add(aValue1);
_AllValue aValue2 = new _AllValue();
aValue2.valueName = "VAL2Name";
aValue2.Values.Add("Val2");
xobj.fieldValues.Add(aValue2);
}
// Works if I use this method
static void popxmlobj(_xobj xobj)
{
for (int i = 0; i < 2; i++)
{
if (i == 0)
{
_AllValue aValue1 = new _AllValue();
aValue1.valueName = "VAL1Name";
aValue1.Values.Add("Val1");
xobj.fieldName = "FieldName1";
xobj.fieldValues.Add(aValue1);
}
if (i == 1)
{
_AllValue aValue1 = new _AllValue();
aValue1.valueName = "VAL2Name";
aValue1.Values.Add("Val2");
xobj.fieldValues.Add(aValue1);
}
}
}
}
}
</code>
<b>pre>Second file</pre></b>
<code>
using System;
using System.Collections.Generic;
using System.Text;
namespace xpop
{
public class _xobj
{
public string fieldName;
public List<_AllValue> fieldValues = new List<_AllValue>();
}
public class _AllValue
{
public string valueName;
public List<string> Values = new List<string>();
}
}
</code>
mohsenb55
-- modified at 10:07 Friday 15th June, 2007
|
|
|
|
|
mohsenb55 wrote: static void popxmlobj1(_xobj xobj)
{
_AllValue aValue1 = new _AllValue();
aValue1.valueName = "VAL1Name";
aValue1.Values.Add("Val1");
xobj.fieldName = "FieldName1";
_AllValue aValue2 = new _AllValue();
xobj.fieldValues.Add(aValue2);
aValue2.valueName = "VAL2Name";
aValue2.Values.Add("Val2");
xobj.fieldValues.Add(aValue2);
}
This code adds aValue2 to xobj twice, I assume this is not right ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Christian,
aValue2 is actually aValue1 I mistyped it. The problem is that I like to instantiate the _AllValue class only one time and re-use the same object multiple times. In the above code to get it to work, the _AllValue class is instantiated twice aValue1 and aValue2. I want to be able to re-use the same object, let's say _AllValue aValue = new _AllValue(); and re-use as many times I want too and not have to intantiate _AllValue twice.
Thanks for the response
|
|
|
|
|
I have a text file of the following format
"apple","orange","pear" etc
I have tried both char and string seperators but can't think of a way grab the data cleanly without including a " or , . I either end up with "apple" "orange" "pear" or "apple orange pear"
The code I have been using.
private static char[] charSeperator = new char[] { ',' };
private static string[] strSeperator = new string[] {"\",\""};
strArray = strLine.Split(charSeperator);
strArray = strLine.Split(strSeperator,StringSplitOptions.None);
Is there a simple way of grabing apple orange and pear from the text file, without having to do further data cleaning?
Thanks in advance for any help you can offer
Haz
|
|
|
|
|
You may want to try regular expressions...
"too much daily WTF for someone..." - Anton Afanasyev
|
|
|
|
|
Sorry Paul what do you mean by regular expressions? I'm only fairly new to this c#
Haz
|
|
|
|
|
|
Giorgi Dalakishvili wrote: http://www.regular-expressions.info/[
That looks like a bookmark worthy site to me
"too much daily WTF for someone..." - Anton Afanasyev
|
|
|
|
|
haz13 wrote: what do you mean by regular expressions? I'm only fairly new to this c#
Being new is cool. Regular expressions are a finite state automaton that work with search patterns, etc.
Take a look at this article:
Expresso[^]
"too much daily WTF for someone..." - Anton Afanasyev
|
|
|
|
|
Thanks for that info guys, I'll go away and have a read up on it
Haz
|
|
|
|
|
using System.Text.RegularExpressions; // the namespace for using Substring
strArray = strLine.Split(new char[] { ',' }; // Use this still, but with the modifications below
foreach (string fruit in strArray) // a loop that runs for every piece of fruit in strArray
{
int fruitlength = fruit.Length; // getting the length of the fruit string
fruitlength = fruitlength - 2; // subtracting 2 because of quotes
string trimmedfruit = fruit;
trimmedfruit = fruit.Substring(1,fruitlength);
// basically the method Substring(start,length)
// and the first letter starts at 0 and length is how many you want to cut out
// so I took the total length of string "apple", subtracted 2 because of quotes
// then started the trim at 1 just after the first qoute and pulled out all the letters
// minus the qoutes
}
|
|
|
|
|
jblouir wrote: using System.Text.RegularExpressions; // the namespace for using Substring
Sorry, but, what are you thinking ? Substring is a method on a class, you don't need a namespace to call it.
string trimmedFruit = fruit.Replace("\"", "");
is even easier.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Your right, didn't realise.
Still learning, on week 1 and a half now.
At the point when I was learning how to use regular expressions I must have stumbled on to substring and assumed it was part of the namespace.
and I didn't know replace even existed
|
|
|
|
|
If you didnt understand his code above.
string trimmedFruit = fruit.Replace("\"", "");
its basically a \" in there so every " it finds it replaces it with "" // e.g. null
using the \ allows you to put a " in the string text
|
|
|
|
|
<blockquote class="FQ"><div class="FQA">haz13 wrote:</div>I have tried both char and string separators but can't think of a way grab the data cleanly without including a " or , . I either end up with "apple" "orange" "pear" or "apple orange pear"</blockquote>
I used similar code to split it. Heres some code, maybe it can help u.
Input text same as u : "apple","orange","pear" etc
assume the string named "str"
<pre>
string[] strArray = str.split(',');
for (int i=0;i<strArray.length;i++){
strArray[i] = strArray[i].trimStart('"');
strArray[i] = strArray[i].trimEnd('"');
}
</pre>
Training makes perfect....
|
|
|
|
|
I want to write a plugin for ms word.Is that possible in c#.
If the answer is yes , How?
Mori Nei
|
|
|
|
|
yes its possible. The correct term is "com add-in". Why not google ms word add-in c#, there are dime a dozen articles. Or visit msdn forums.
edit
try this link
http://www.google.com/search?lr=&ie=UTF-8&oe=UTF-8&q=ms%20word%20add-in%20c%23
|
|
|
|
|
Hello everyone,
I was wondering if someone can take a moment and explain to me the differences between DataTable and DataSet. I have been using both of them and to be honest with you, never undrestood the differences between them.
Maybe they have some specific differences which results in favoring one over the other when it comes to certain things. Saddly, I have never seen that and I use them in a random fashion. )
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
Easy. A DataSet is a collection of DataTable and DataRelation objects. You can have one or more DataTables in a DataSet. DataRelation objects just represent the relationships between related tables.
|
|
|
|
|
Hello Dave,
Thank you so much. Please don't laugh, but after your explaination alot of things made sence.
Once again, thank you very much for your help, mate.
Have a great day.
Khoramdin
|
|
|
|
|
I have a network application that runs in a thread for it self, my main application subscribes to the events the network application fires (such as SignedIn, ExceptionOccured and so on).
My problem is that when a event in the other thread if fired, I want to disable/enable and change a lot of stuff in my main application GUI.
But for every change I want to make in my main application, I have to write a delegate and invoke it.
This gives me A LOT of code that is only used once, and it just seems stupid.
Is there a way of executing a method with invoke without declaring a delegate?
I have an example to demonstrate my problem:
public class MyClass<br />
{<br />
<br />
public MyClass()<br />
{<br />
...<br />
myThread.SignOut += SignOut;<br />
}<br />
<br />
public void SignOut()<br />
{<br />
myForm.ShowLogin();<br />
}<br />
}
|
|
|
|