|
You might want to have a look at this project then. C# Synth Toolkit - Part I[^] I think it accomplishes what your looking for and then some.
Fear not my insanity, fear the mind it protects.
|
|
|
|
|
TcpClient.cs
namespace TCP_Communication
{
public class TcpClient
{
public delegate void DataArrivalDelegate(char[] data);
public DataArrivalDelegate OnDataArrival = null;
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace TCP_Communication
{
public class Program
{
static void Main(string[] args)
{
TcpClient Client = new TcpClient();
Client.OnDataArrival = new TcpClient.DataArrivalDelegate(OnDataAvailable);
}
public void DataArrived(char[] newdata)
{
}
}
}
Error:
'OnDataAvailable': cannot reference a type through an expression; try 'TCP_Communication.TcpClient.OnDataAvailable' instead
I'm new to C#.
I read the article in MSDN about C# delegates, but still I can't find what I'm missing.
Can you please help me fix this problem?
Thanks.
|
|
|
|
|
Your handler has to be declared as "static", just like Main().
|
|
|
|
|
Just curiosity, can tell me why does it has to be static?
|
|
|
|
|
Because you're not creating an instance of the Program class, but rather just using it as a container for the Main() method.
Basically, a static method operates on an entire class/type, while an instance method (non-static) operates on a single object of that type.
|
|
|
|
|
To add to Ian's answer, an instance method can access both static and other instance methods, but a static method can only access other static methods. Since Main is static, it cannot access instance method of the Program class.
Dybs
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
|
|
|
|
|
Also this :
Client.OnDataArrival = new TcpClient.DataArrivalDelegate(OnDataAvailable);
Probably needs to be changed to this:
Client.OnDataArrival = new TcpClient.DataArrivalDelegate(DataArrived);
or better:
Client.OnDataArrival = DataArrived;
Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
I figure he just copy-pasted it wrong, or he'd be getting an entirely different error
|
|
|
|
|
Hey Guys,
I have a string consisting of zeros and ones like 10101010
I want to read each letter then convert it to code and use it ... I've checked the function Split() but it requires a character, and as u see mine doesn't have any.
Regards,
K
|
|
|
|
|
Just use - ToCharArray()
string strTest = "1100110101";
char[] cList = strTest.ToCharArray();
modified on Friday, April 16, 2010 7:33 AM
|
|
|
|
|
This is okay unless you don't want to allocate more memory in the process. Using string.Substring() would be a viable alternative.
(I still marked your response as a "good answer". )
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
Yes, thanks for pointing that out..
Regards,
Neh
|
|
|
|
|
Try using the Substring method of a string .
|
|
|
|
|
Hi Abhinav,
Isn't string.ToCharArray() a better way than using string.SubString() ?
Thanks,
Ram
|
|
|
|
|
I have to ask - what does the string represent? A series of flags?
If so, you could convert it to an integer, and then access it with logical AND (&) and logical OR (|) operators. Math operations are always faster/more efficient than string operations.
To convert the string to an int, do this:
string myString = "10101010";
int flags = Convert.ToInt32(myString, 2);
At that point, you can do this:
int myVal = 4;
if ((myVal & flags) == myVal)
{
}
.45 ACP - because shooting twice is just silly ----- "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." - J. Jystad, 2001
|
|
|
|
|
I figured it out, by using string[x] I have access to each character of my string !
each character is a code, I'm trying to store days for a class so for instance its 1000000, it means its only Saturday, or 1010100 means it's on Saturday, Monday and Wednesday.
Regards,
K
|
|
|
|
|
Well, then you can do that more cleanly if you want...
[Flags]
public enum DayFlags
{
Saturday = 64,
Sunday = 32,
Monday = 16,
Tuesday = 8,
Wednesday = 4,
Thursday = 2,
Friday = 1
}
public static bool IsFlagSet(this DayFlags en, DayFlags flag)
{
return ((int)en & (int)flag) != 0;
}
DayFlags days = (DayFlags)Convert.ToInt32(str, 2);
if (days.IsFlagSet(DayFlags.Sunday)) { ... }
|
|
|
|
|
John Simmons / outlaw programmer wrote: Math operations are always faster/more efficient than string operations.
Unless you run out of fingers and toes, then have to resort to paper and pencil.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
lol true ... that works all the time but due to the fact that we are getting lazier everyday these things become vital in our lives ! don't u agree ?
|
|
|
|
|
Good Morning everybody,
I develop a csharp smart device application.I am in the step of the connection to my local database .sdf.As I read,I should add this .sdf file to my emulator using a shared folder.I did as below:
1-sharing my file C:\Users\Admin\Documents\Visual Studio 2008\Projects\GMAOMobile
2-in the visual studio,go to Tools->connect to device
3-in the device tool,Menu File->configure...
4-I add the shared file in the shared folders icon.
Running another time,the problem still the same:cannot found the path of the database.
I read more.I found that I can refer to my database using the storage card.But I can't Copy the DB (the sdf file) from the pc to the storage card, and, and refer to it as \\Storage card\GMAOMobile.sdf.
Any help will be very grantful
Regards
|
|
|
|
|
Tunisien86 wrote: But I can't Copy the DB
It would be helpfull if you stated why you can't copy the file. Did you receive an error?
It might be easier if you copy the CE-database to a shared folder on your device, as opposed to reading it from an occasionally-connected-drive. I suggest you dive into the documentation[^].
I are Troll
|
|
|
|
|
|
Tunisien86 wrote: Plzzzzzzzzzzz help me
I am really getting crazy
Save your SqlCe database on the SmartDevice itself, and point your connectionstring to it. That's also what's been suggested as an answer in the post that you are referring to;
conn = @"Data Source=\Program files\smartdeviceproject1\firstaid.sdf";
As you can see, there's no C:\ drive on a smart device. Your app will be deployes domewhere in the "Program Files" folder. I suggest you share that folder and copy your file there, and update your connectionstring accordingly.
I are Troll
|
|
|
|
|
|
Hello community!
I'm new here. My Question is:
Is it possible to create a TableAdapter programmatically or deliver it to an extern function?
The reason:
I want to create an Class Library which should take care of DataBase activities in my application.
One reason is a function i wrote that compares the loaded Row with the Row in DataBase before sending an Update-Command, which i want to use in all applications.
My consideration:
The Library contains an class "DBCaretaker". On creating this class, it receives the DataSet and the TableAdapters. After that, filling DataSets, Updating Tables and further actions will be executed by functions in this Library.
Is this possible? Or do you have an alternative proposal?
Greetings,
Robert
|
|
|
|