|
Quick ? What sort of subject line is that ?
The obvious solution is a Dictionary, that's what they are for.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: Quick ? What sort of subject line is that ?
An extremely poor one, my error - we all make them from time to time
Christian Graus wrote: The obvious solution is a Dictionary, that's what they are for.
Yes, however as mentioned in the original post, I am working with classes generated by the XSD tool. As such I need underpin the stringdictionary with the simple arrays this tool creates and keep the array and the dictionary in synchronisation as code adds, removes, edits values. Unfortunately this is where I am not sure where to go or what to do.
|
|
|
|
|
WEll, you really cannot lookup by string unless you build a container that works that way. Why not just build a dictionary at the point of deserialising the list, then use that for lookups ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Well thats the idea, wrap the base array with a StringDictionary. However I need to keep the StringDictionary and base array in sync as code adds/edits/removes items regardless of whether this is done by string key on integer index.
So the question is how to do it?
|
|
|
|
|
I guess you need to write a class which contains an array and a dictionary, so that you only add/remove/access items via the interface of that class, which then ensures they are kept in sync
Or, you could use the Values collection of your dictionary as your plain vanilla list of items ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: The obvious solution is a Dictionary
And they work brilliantly.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Yes they do, however what I don't know how to do is encapsulate the XSD tool generate simple array with a StringDictionary while keeping everything in sync and not breaking the (de)serialiser, and therefore allow the following:
string val1 = widget[0]
string val2 = widget["mykey"]
Console.Writeline(val1 == val2)
Which would output true
|
|
|
|
|
If you're using XML, use an XmlDocument.
It sounds like your "XSD tool" is causing you more trouble than it's worth.
|
|
|
|
|
Hi
I have a ToolStripContainer where I only use the top and bottom. I set up serveral ToolStrips that I placed into the ToolStripContainer. The ToolStrips are small enough to fit all in one row (on a normal screen). Now, I like to show/hide these ToolStrips based on user action. And besides shwoing I also like to rearrange them. Now here is the problem. What ever I do they get mixed up and are not displayed at the Location I told them.
Basically I do this :
<br />
int x = 0;<br />
switch(_type) {<br />
case PropertiesItemMode.Text:<br />
toolStripText.Visible = true;<br />
toolStripMedia.Visible = false;<br />
toolStripMenu.Visible = false;<br />
toolStripPositionProperties.Visible = true;<br />
toolStripScaleProperties.Visible = true;<br />
<br />
x = 0;<br />
if (toolStripInfo.Visible) {<br />
x += toolStripInfo.Size.Width;<br />
}<br />
<br />
toolStripPositionProperties.Location = new Point(x, 0);<br />
x += toolStripPositionProperties.Size.Width;<br />
<br />
toolStripScaleProperties.Location = new Point(x, 0);<br />
x += toolStripScaleProperties.Size.Width;<br />
<br />
toolStripText.Location = new Point(x, 0);<br />
<br />
break;<br />
case PropertiesItemMode.Menu:<br />
toolStripText.Visible = false;<br />
toolStripMedia.Visible = false;<br />
toolStripMenu.Visible = true;<br />
toolStripPositionProperties.Visible = true;<br />
toolStripScaleProperties.Visible = false;<br />
<br />
x = 0;<br />
if (toolStripInfo.Visible) {<br />
x += toolStripInfo.Size.Width;<br />
}<br />
<br />
toolStripPositionProperties.Location = new Point(0, 0);<br />
x += toolStripPositionProperties.Size.Width;<br />
<br />
toolStripMenu.Location = new Point(150, 0);<br />
<br />
break;<br />
}<br />
<br />
Any idea what I am doing wrong here ?
Thanks
-Sebastian
|
|
|
|
|
Here's an example of what I'm doing.
public class MyObject1 {}
public class MyObject2 {}
public class MyData
{
public MyObject1 myObj1;
public MyObject2 myObj2;
public void SetData(MyObject1 ojb1, MyObject2 obj2)
{
myObj1 = obj1;
myObj2 = obj2;
}
}
public partial class MyForm
{
private MyObject1 myObj1;
private MyObject2 myObj2;
private void MyFunction()
{
MyData data = new MyData();
data.SetData(myObj1, myObj2);
}
}
I don't understand why this should generate an accessibility error during the compile.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Friday, May 9, 2008 7:26 AM
|
|
|
|
|
Well, this will not compile, as it happens, but once I fix the syntax errors, it builds just fine.
John Simmons / outlaw programmer wrote: public SetData(MyObject1 ojb1, MyObject2 obj2)
needs to be
public void SetData(MyObject1 obj1, MyObject2 obj2)
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Yeah, forgot the void, but it won't compile for me in my app (admittedly much larger and complex than the example I posted).
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Probably the best way to check this is to start systematically checking the properties and methods on your publically exposed types that expose something that isn't publically accessible. Obviously, starting with the one that caused the compilation error.
|
|
|
|
|
If an abstract class contains one method with only declaration and with no body, will it gets executed with no errors? Thanks in advance
|
|
|
|
|
Hi,
yes the code will be executed as the Abstract Classes are not used to create objects.
An abstract class is designed to act as a base class (to be inherited by other classes). Abstract class is a design concept in program development and provides a base upon which other classes are built.
To know more about the same, please refer to the below mentioned link:
[^]
http://www.codeproject.com/KB/cs/jmabstractclasses.aspx[^]
Hope this helps.
Vinay
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
Well, you can't really execute an abstract method. A class would have to be derived from the abstract class and implement the abstract method. Then you can execute the actual method.
An abstract class may contain a non-abstract method, it will require a body, but that body may be empty (or at least an appropriate return statement).
|
|
|
|
|
Hello everyone,
Meta data for an assembly describes the exposed and referred types of the assembly. I am wondering the the debug version and release version of the assembly, are the meta data the same or not?
thanks in advance,
George
|
|
|
|
|
Well, depends what you mean. Some of it has to differ, but the 'exposed and refered types' obviously do not.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Christian,
Christian Graus wrote: Some of it has to differ
I am wondering what are the differences?
regards,
George
|
|
|
|
|
I have a C#-Component with some logic implemented.
This logic is used from my web application and a C++ application.
Debugging the C#-Component from the web application is no problem.
But now I am faced with the problem to debug the C#-component from the C++ application which is unmanaged code.
If I start the application and try to attach the debugger after that, the MS Visual Studio 2003 raises an error message with the following info:
"Unabled to attach to the process. There is no managed code running..."
So I tried the following. I made (for debugging only) a global instance of my C#-component with is loading at start up of the C++ application. Now, when I try to attach the debugger the MS VS says only:
"Unabled to attach to the process." So the debugger noticed my managed code running but he cant attach nevertheless.
So do you have any ideas what the problem could be?
Thanks in advance.
Erik
|
|
|
|
|
I wish to build a multi sized array to read data from a specific source (in this case an SQLDataReader). The following code DOES work however it seems fairly drawn out and I'm certain that it could be done in less code. I'm fairly new to C# hence why I think my way of doing it possibly isn't the most efficient.
Without giving the array a size I get a compiling error and thus have to have two while loops to give the array a size. Is there a better way to do this?
Many thanks.. Ant
MSSQLConn.Open();
SqlCommand MSSQLCommandSelect = new SqlCommand();
MSSQLCommandSelect.CommandText = "SELECT TrackingID FROM Tracking WHERE " + FieldToSearch + " = " + DataToSearch;
MSSQLCommandSelect.Connection = MSSQLConn;
SqlDataReader reader = MSSQLCommandSelect.ExecuteReader();
int[] TrackingIDs;
int i = 0;
while (reader.Read() == true)
{
i++;
}
reader.Close();
reader = null;
reader = MSSQLCommandSelect.ExecuteReader();
TrackingIDs = new int[i];
i = 0;
TrackingIDs[0] = -1;
while (reader.Read() == true)
{
TrackingIDs[i] = (int)reader[0];
i++;
}
reader.Close();
MSSQLConn.Close();
return TrackingIDs;
|
|
|
|
|
|
Only use ArrayList if you're stuck with .net 1.1, if you have 2.0 and above you're better off using the generic List.
He who makes a beast out of himself gets rid of the pain of being a man
|
|
|
|
|
Thank you I shall give both those options a try.
ta - ant
|
|
|
|
|
Hi,
I want to write a GENERIC method to retrieve a property from an object from the specified index.
For example, I have three classes as listed below . OrderHeader contains a list of OrderDetail and OrderDetail Contains a list of OrderItem.
public class OrderItem<br />
{<br />
private int _itemId ;<br />
<br />
public int ItemId<br />
{<br />
get { return _itemId; }<br />
set { _itemId = value; }<br />
}<br />
private string _ItemName ;<br />
<br />
public string ItemName<br />
{<br />
get { return _ItemName; }<br />
set { _ItemName = value; }<br />
}<br />
}<br />
<br />
<br />
public class OrderDetail<br />
{<br />
<br />
private IList<OrderItem> _orderItemList;<br />
private int _orderDetailId;<br />
private int _amount;<br />
<br />
public IList<OrderItem> OrderItemList<br />
{<br />
get { return _orderItemList; }<br />
set { _orderItemList = value; }<br />
}<br />
<br />
public int OrderDetailId<br />
{<br />
get { return _orderDetailId; }<br />
set { _orderDetailId = value; }<br />
}<br />
<br />
public int Amount<br />
{<br />
get { return _amount; }<br />
set { _amount = value; }<br />
}<br />
}<br />
<br />
public class OrderHeader<br />
{<br />
private int _orderHeaderId;<br />
private IList<OrderDetail> _orderDetailList;<br />
<br />
public int OrderHeaderId<br />
{<br />
get { return _orderHeaderId; }<br />
set { _orderHeaderId = value; }<br />
}<br />
<br />
public IList<OrderDetail> OrderDetailList<br />
{<br />
get { return _orderDetailList; }<br />
set { _orderDetailList = value; }<br />
}<br />
<br />
}
First input to the method is an object (Example: OrderHeader Object)
Second input is a string with the required propety name and stirng. --> "OrderHeaderObject.OrderDetailList[1].OrderItemList[0].ItemName".
And the output should be the ItemName string.
What would the best way to acheive this..?
Can i achive it by using the method InvokeMember() method..? Example: OrderHeaderObject.GetType().InvokeMember(....)
Where did error begin?
-- Naison Garvasis Pekkattil
|
|
|
|