|
|
What exactly do you want to get as output xml? can you please give an example?
|
|
|
|
|
Hi everybody,
I was looking a java code, and I would like to translate to C#, but I don't know if this feature exits in c#. The code is this:
public class Controller implements IController{
private State state;
private Speed speed;
private ProductHandler producthandler = new ProductHandler (){
@Override
public void changeState(State newState) {
state = newState;
}
@Override
public Speed getSpeed() {
return mds;
}
@Override
public void send(Packet pk) {
outputQueue.add(pk);
}
@Override
public void setSpeed(Speed newSpeed) {
speed = newSpeed;
}
};
ProductHandler is a class defined inside other class "dinamically". ProductHandler can access Controller attributes. Is this possible in C#? I have done it with events and so... but its very dirty. Is this annonymous classes, am i right? Is there something equivalent in .net 2.0?
Regards
modified on Friday, January 8, 2010 2:50 PM
|
|
|
|
|
C# has anonymous methods, but not anonymous classes. Maybe because you can use delegates, so there is no need for a whole class.. (according to the designers)
Anonymous methods can access the variables of the place they were declared in as well
|
|
|
|
|
I don't know Java, so I'm guessing a bit!
If you want to declare a new class nested inside another, you can and the nested class can access all members of the outer class.
If you want to extend an existing class, you can derive from it. Another option is to use extension methods, although they can only access the public members of the original class.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Thanks to both.
Nick, I have tried to do as you say, but I could't. Could you please paste a little example here?
Thanks in advance
|
|
|
|
|
You could simulate this using dynamic methods. Have a look around this[^] topic.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
ika2 wrote: Is there something equivalent in .net 2.0?
C# don't support anonymous classes. It has support for anonymous types, but it will not help you in this case. I guess what you need can be achieved using nested classes. Nested class will have access to all members of the class where it is written. Here is an example.
public class Controller : IController
{
private State state;
private Speed speed;
public class ProductHandler
{
public void ChangeState(State newState)
{
}
}
}
Best wishes,
Navaneeth
|
|
|
|
|
if i compile my wpf project in xp
and execute it on vista.
will it be executing normally.
i had an experience it from windows form application. it was not ruing on vista. i faced color combination problem.
|
|
|
|
|
hotthoughtguy wrote: if i compile my wpf project in xp
and execute it on vista.
will it be executing normally.
Yes, given that the appropriate version of the .Net framework is installed.
hotthoughtguy wrote: i had an experience it from windows form application. it was not ruing on vista. i faced color combination problem.
If you're talking about color combination problems in the user interface, they are the fault of the programmer, not the operating system.
.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
|
|
|
|
|
but the same win form project is executing normal in xp. if programming fault is there. so it should not execute normally in xp as well as vista
|
|
|
|
|
There shouldn't be any problems given that the same framework is installed as was said before. The best way to find out is to try it. if you face problems and you cant figure out solutions, post more questions.
|
|
|
|
|
|
YOu mean Compress method used by NTFS partiton?
This kind is compressed by OS. So it automatcly gets decompressed befpre zse and you do not need to handle it. If there was a need to handle it, then there would be a lot of broken apps
|
|
|
|
|
So I've created this application....
I realized that when it installs, all it installs is just a Shortcut to an Application Manifest.
The problem is, that the server the installer is on that it checks for updates etc.... if it ever goes down then that makes me thing that the shortcut wouldn't work thus the users can't use the program. How do i make it so that my C# program actually Installs the program itself on the users PC and not just a shortcut?
|
|
|
|
|
Are you using Visual studio installer? If yes, take a look at this article[^]
|
|
|
|
|
No, Im using Visual C# Express 2008
|
|
|
|
|
I have to parse html with charset=iso-8859-2. I am getting html string now like this:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(http:
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
int count = 0;
byte[] buffer = new byte[8192];
do
{
count = resStream.Read(buffer, 0, buffer.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buffer, 0, count);
html += tempString;
}
}
while (count > 0);
Now specials are showed like ? or smt, because they aren't in ASCII range. How could i parse it with special chars showed normally?
Thanks,
Bye
|
|
|
|
|
Aljaz111 wrote: tempString = Encoding.ASCII.GetString(buffer, 0, count);
You asked for it in ASCII, perhaps you should use Unicode.
|
|
|
|
|
Seems like ISO 8859-2[^] stands for the Central European character set. So I would go for an 8-bit encoding, most likely new Encoding(12xx) is all it takes. It certainly won't work properly with ASCII, as that only accepts character codes [0, 127].
For you to read[^].
|
|
|
|
|
Ok i did it like this:
Encoding e=Encoding.GetEncoding(1250);
Still all chars aren't showed as they should be. One of them is showed right..for others I used replace
Thanks
|
|
|
|
|
How i can check if my gateway connected to internet (online) or not (offline) using C# ?????????????
|
|
|
|
|
Try to ping something in c#. If it succeeds, you are connected
|
|
|
|
|
You should also set the TTL to 2 to make sure there's not other "random Internet problem" causing your ping to fail. (Assuming that your gateway is 1 hop away).
|
|
|
|
|
Hi Matt Meyer
i thank u for intersting, but i need that using coding ..........
|
|
|
|