|
Hello
Is there bidirectional iterator(it is desirable for generics) in C#? (May be third party implementation).
Andriy
|
|
|
|
|
There isn't one that I can recall, however, it is relatively easy to make one using the yield keyword in 2.0
only two letters away from being an asset
|
|
|
|
|
Mark, thank you for advice. I think you've meant smth like this:
public IEnumerator<t> GetEnumerator() {
if (left != null) foreach (T x in left) yield x;
yield value;
if (right != null) foreach (T x in right) yield x;
}
But I need calling "MoveNext" and "MovePrevious" in arbitrary order e.g.: "MoveNext", "MoveNext", "MoveNext", "MovePrevious", "MoveNext", "MoveNext".
If you know how to implement discribed behaviour using "yield" please write small code snippet. I haven't found how to do it after investigating C# Specification describing "yield".
I think possible solution can be wrapping LinkedList.
What do you think about this?
|
|
|
|
|
|
Mark, but this sample likes code snippet I've sent you in previous post. It doesn't fit for my task. Because I need calling several "MoveNext" in the side of "Top" not reaching the last element and then call "MovePrevious"(IEnumerator doesn't contain it at all). How can you do it using sample you've sent?
|
|
|
|
|
Sometimes you need to do more than cut & paste. You have all the tools necessary to create what you are asking for. Right, IEnumerator does not have a MovePrevious method, so create one.
only two letters away from being an asset
|
|
|
|
|
Hello
I don't know why you are making things compicated for yourself?? Random access collections work fine in most scenarios!! If you don't want to wrapp an iterator to implement what you need, well, here is a simple - poor pratice- way to simulate what you need.
1- Make a private random access collection. eg. ArrayList
2- Make a private integer to store the current index
3- Make a public object of the type you want to store in the ArayList.
4- Make to public methods MoveNext() , MoveBack() , to increase/decrease the CurrentIndex and store MyIterator[CurrentIndex] in ther public object you created.
Regards
|
|
|
|
|
Thank you, this is what I am about to implement. I've just hoped that there is already implemented bidirectional up-to-date for changes iterator.
|
|
|
|
|
Hello,
I am trying to implement drag within my shell namespace extension. I noticed that in MFC you are able to set up a message area to attach to the events such as OnBeginDrag.
My question is; How do I attach to those events using c#?
Thank you,
Rick
Rick
Rick
|
|
|
|
|
They hide that information in the Documentation[^]
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
Yes,
I get that part about the event, but How do i attach to an event that is sent by the windows shell.
Rick
|
|
|
|
|
Rick, with a little Googling i found this CodeProject Article[^] maybe it will help
"Alot of the people on this forum are incredibly stupid, thinking that the internet is real" Score: 1.0 in the Soap Box
led mike
|
|
|
|
|
hi,
i would like to make a serial communication with an antenna to send and recieve data from another antenna, the first one is connected on a com port of my pc. i program it in visual studio 2003
but i dont know how to start
does anybody know a site with samples that could help me?
thxx
|
|
|
|
|
serial communications are much easier using the provided System.Ports.Serial class in VS05. IF you're unable to use the (free) express edition of 05, there are several user written libraries available on this site if you use the search function.
|
|
|
|
|
Hello
To access any port -Serial, LPT, USB, etc...- or device -eg. modem- in C3 you follow these steps:
1- Call Windows API CreateFile() function with the device name as the filename. ie. CreateFile("COM1") for example.
2- Get The handle of the created file.
3- Supply that handle to the constructor of a FileStream object.
4- Use that FileStream object to read and write from/to the port/device.
And no, you can't construct a FileStream from the port directly. Sorry!
Regards
|
|
|
|
|
I'm trying to open a database connection via my app.config file however my connection string keeps coming back as NULL.
Here's my app.config file:
----------------------------------
<connectionStrings>
<add name="DBConn" connectionString="Data Source = myDataSource;Initial Catalog = catalogName;User Id =myUserId;Password = myPword;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
-------------------------------------
Here's the code I'm using to open my connection. The "settings" variable keeps coming back as null:
---------------------------------------
string cnString = null;
// Look for the name in the connectionStrings section.
ConnectionStringSettings settings =
ConfigurationManager.ConnectionStrings["DBConn"];
// If found, return the connection string.
if (settings != null)
cnString = settings.ConnectionString;
connection = new SqlConnection(cnString);
connection.Open();
------------------------------------------------
Do I perhaps have my app.config in the wrong location? I placed it in the root directory of my project (located alongside my project and ".cs" file).
Thanks in advance.
-Goalie35
|
|
|
|
|
Looks ok to me!
Have you got the <connectionStrings> under <configuration> (where it should be) and not in the app settings or something like that?
Regards,
Rob Philpott.
|
|
|
|
|
Hi Rob. Thanks for replying.
My full app.config looks like the following:
-------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="ReportDBConn"
connectionString="Data Source = myConnectionString;Initial Catalog = catalogName;User Id =myuserId;Password = myPword;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
---------------------------------------------------
Thanks again.
-Goalie35
|
|
|
|
|
Are you able to see <yourexename>.app.config in the bin/Debug (or Release) directory? Did you add your app.config manually or through the Add Items menu in VS .NET? If it's the former, then VS .NET doesn't generate exename.app.config automatically.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi
How does .NET split the command line arguments to generate the args[] array?
Does it just to a string.Split(fullCommandLine, ' ') ?
If yes, will this code be correct to complely restore the full command line?
string parameters = "";
foreach (string s in args)
{
parameters += " " + s;
}
parameters.TrimEnd(' ');
The reason behind is this question is that I have to use the complete command line, because I parse a parameter that uses a file path like -file="C:\Documents and Settings"
This will be split by .NET. In C++ we had a lpCommandLine which contained the complete command line. Does my loop do the same thing?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
yes it is but you should replace parameters.TrimEnd(' '); by parameters=parameters.trim();
|
|
|
|
|
Okay thanks.
I wanted to edit my post to change it to "Trim", but the operation always fails with an error message. I hate this server
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
If you want the complete command line use Environment.CommandLine .
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
Yeah, but this also includes the executable path.
So either I remove that one or use my loop, makes not much difference
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
In my c++ code, I have a struct which has a dynamically allocated array. Now in c# code, I want to declare the same struct in a proper way so that I can call c++ native code from c#.
If in C++ I have the following:
struct A {
int * arrInt;
};
typedef struct A A_STRUCT;
void func(A_STRUCT * ptrStruct);
How would I declare the struct in c# and also how to define the function "prototype" when doing dllimport? Thanks a lot.
|
|
|
|