|
This[^] is in VB but may help.
Dave
|
|
|
|
|
Do you have any sample on how to use this?
|
|
|
|
|
The full thread is here[^] - there's an explaination of the code at the bottom by the author.
Dave
|
|
|
|
|
Having looked in more detail I think that thread is a little over-complicated.
Why not use the CultureInfo class? If you're going to be using it alot it could be useful to set it as an extension method something like this.
using System.Globalization;
namespace Indian
{
public static class ExtMethods
{
public static string ToIndian(this double amount, bool includePrefix)
{
CultureInfo indianCulture = new CultureInfo("hi-IN");
string indianString = amount.ToString("C", indianCulture);
if (includePrefix)
{
return indianString;
}
return indianString.Substring(2);
}
}
}
then add using Indian; to the beginning of any class that needs it.
You can then easily call the method on any double value (change it to other value type if required!).
double doubleIndian = 1234567.89;
string stringIndian = doubleIndian.ToIndian(false);
Dave
|
|
|
|
|
I'm just starting out learning C# and am having trouble sending a message between a client and server over a UDP connection. I'm thinking it's my code, maybe the server side because when I load the server my GUI does not show unless I take out the line "recv = server.ReceiveFrom(data, ref remote);". I'm using Visual Studios 2005 and any help is appreciated. If you have any advice or tutorials that could help me get a better grasp on working with C# in general, it would also be appreciated. Thanks!
Server:
Socket server;
public Message_Server()
{
InitializeComponent();
int recv;
String receiveData;
server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
EndPoint remote = (EndPoint)remoteEP;
Byte[] data = new Byte[1024];
server.Bind(remote);
//while (true)
//{
recv = server.ReceiveFrom(data, ref remote);
//data = server.Receive(ref remoteEP);
receiveData = Encoding.ASCII.GetString(data, 0, recv);
//receiveData = Encoding.ASCII.GetString(data, 0, data.Length;
displayBox.Text = receiveData;
//}
}
Client:
private String IPAddr = "192.168.1.101";
private int portNum = 7000;
private bool err = true;
Network_Input NI = new Network_Input();
Socket client;
public Message_Client()
{
InitializeComponent();
}
private void sendBtn_Click(object sender, EventArgs e)
{
client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(IPAddr), portNum);
try
{
String message = "Hello World";
byte[] data = System.Text.Encoding.ASCII.GetBytes(message);
client.SendTo(data, data.Length, SocketFlags.None, remoteEP);
}
catch (SocketException)
{
MessageBox.Show("Socket Exception");
}
}
Thanks Again!
|
|
|
|
|
Where do you define the sending port in the server part?
|
|
|
|
|
Hi all,
How can i update exe file after i install the application in user PC? For vb application, i can just replace the existing exe file with the updating exe file in program directory.But how can i do it in C#?
any tips are welcome.
Thanks in advance
cocoonwls
|
|
|
|
|
Once your app has detected that a new version is available, you could exit your app and run a companion updater program that performs the download and overwrite (and optionally restarts your app).
/ravi
|
|
|
|
|
Ravi Bhavnani wrote: run a companion updater program
Hi ravi, can you please tell me more details how to execute it in my program?Thanks
|
|
|
|
|
See this[^] CP article.
Sorry, that's a C++ article.
Basically the updater needs to restart your app after successfully updating it by downloading the new bits. Use Process.Start() [^] to restart the app.
/ravi
|
|
|
|
|
Can anyone please tell me how to catch an cell change event due to formula, for example if at cell A3 has got formula =A1+A2, now if the value of A1 has changed then it reflects the value A3 too, but I am not able to get the cell change event on that.
I have got following KB article for that, it catches cell change event but not catch if a value of cell is changed due to a formula.
http://support.microsoft.com/kb/823981[^]
Thanks,
Mushq
|
|
|
|
|
Hi there,
I am trying to find information about the file metadata in Windows. Every file
has a summary tab page in its general properties. Where is that information stored?
I want to access and modify this data (the Keywords field in particular) from within C#.
I couldn't find anything useful online. Maybe some of you guys can enlighten me.
cheers from Germany...
|
|
|
|
|
Ok, before you read all the code I am Telling you this IS a homework assignment. My professor is not helping out very much with it (for me) and I just do not understand how to get this working. I would like to not have the code handed to me but would like some good advise on how to complete this.
namespace IT274_U2
{
public interface IAnimal
{
string WhatAmI { get; }
string WhatIsMyName { get; }
}
abstract class Animal : IAnimal
{
private string _WhatAmI;
private string _WhatIsMyName;
public string WhatAmI
{
get
{
return _WhatAmI;
}
}
public string WhatIsMyName
{
get
{
return _WhatIsMyName;
}
}
}
class Dog : Animal
{
}
class Cat : Animal
{
}
public class TesterClass
{
static void DescribeAnimal(IAnimal animal)
{
Console.WriteLine("My name is {0}, I am a {1}", animal.WhatIsMyName, animal.WhatAmI);
}
static void Main(string[] args)
{
Dog mydog = new Dog("Dog", "Spot");
Cat mycat = new Cat("Cat", "Felix");
DescribeAnimal(mydog);
DescribeAnimal(mycat);
}
}
}
Ok I have the Interface IAnimal. Now I needed to make an abstract class Animal (required). Ok Now how do I implement new dog() and new Cat() if I cannot include another public void Dog(string _WhatAmI, _WhatIsMyName) ?? Because that has to be in there somewhere because it requires 2 arguments?!?!
I am way confused on this....
|
|
|
|
|
First off, in your Animal class you will need to change the _WhatAmI and _WhatIsMyName variables to protected. A protected variable is exactly the same as private except that derived classes can access the variable. If your not sure what I mean, then try to acces the variable _WhatAmI from the Dog or Cat classes and see what happens.
Now, when you call new ClassName it creates a new instance of the class and the classes constructor is automatically called. So, you need to create a constructor for your Dog and Cat classes which takes the two string parameters.
MSDN on access modifiers[^]
Lots of info on constructors[^]
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
Ok it compiles without errors but does not return a value..
I know what is wrong.. assigning _WhatAmI.
But I have to figure out how to assign WhatAmI and WhatIsMyName to _WhatAmI and _WhatIsMyName
right? But it is read-only.
namespace IT274_U2
{
public interface IAnimal
{
string WhatAmI { get; }
string WhatIsMyName { get; }
}
abstract class Animal : IAnimal
{
protected string _WhatAmI;
protected string _WhatIsMyName;
public string WhatAmI
{
get { return _WhatAmI; }
}
public string WhatIsMyName
{
get { return _WhatIsMyName; }
}
}
class Dog : Animal
{
public Dog(string _WhatAmI, string _WhatIsMyName)
{
_WhatAmI = WhatAmI;
_WhatIsMyName = WhatIsMyName;
}
}
class Cat : Animal
{
public Cat(string _WhatAmI, string _WhatIsMyName)
{
_WhatAmI = WhatAmI;
_WhatIsMyName = WhatIsMyName;
}
}
public class TesterClass
{
static void DescribeAnimal(IAnimal animal)
{
Console.WriteLine("My name is {0}, I am a {1}", animal.WhatIsMyName, animal.WhatAmI);
}
static void Main(string[] args)
{
Dog mydog = new Dog("Dog", "Spot");
Cat mycat = new Cat("Cat", "Felix");
DescribeAnimal(mydog);
DescribeAnimal(mycat);
Console.ReadKey();
}
}
}
|
|
|
|
|
Jacob Dixon wrote:
public Dog(string _WhatAmI, string _WhatIsMyName)
{
_WhatAmI = WhatAmI;
_WhatIsMyName = WhatIsMyName;
}
See the problem here is that the variables supplied to the constructor have the same name as the class' variables, which means that the variables in the constructor are hiding the class' variables. Second, you tried to set your properties WhatAmI etc, which only have get implemented, which is why you got the read-only error. The variables you need to set are _WhatAmI and _WhatIsMyName.
What you need to do is something like this:
public Dog(string what, string name)
{
_WhatAmI = what;
_WhatIsMyName = name;
}
So, in this case you would be setting the variables _WhatAmI and _WhatIsMyName which are defined in your abstract class, to the variables what and name which are passed to the constructor.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
I got it to work! Thanks.. let me know what you think about this:
Ok tell me if I am wrong but as you said you do protected string so Dog and Cat have access to it. Now pass the information to Dog() and Cat(). which sets the values for _WhatAmI and _WhatIsMyName in the abstract class Animal. which returns the value for output.. correct?
namespace IT274_U2
{
public interface IAnimal
{
string WhatAmI { get; }
string WhatIsMyName { get; }
}
abstract class Animal : IAnimal
{
protected string _WhatAmI;
protected string _WhatIsMyName;
public string WhatAmI
{
get
{
return _WhatAmI;
}
set
{
_WhatAmI = value;
}
}
public string WhatIsMyName
{
get
{
return _WhatIsMyName;
}
set
{
_WhatIsMyName = value;
}
}
}
class Dog : Animal
{
public Dog(string WhatAmI, string WhatIsMyName)
{
_WhatAmI = WhatAmI;
_WhatIsMyName = WhatIsMyName;
}
}
class Cat : Animal
{
public Cat(string WhatAmI, string WhatIsMyName)
{
_WhatAmI = WhatAmI;
_WhatIsMyName = WhatIsMyName;
}
}
public class TesterClass
{
static void DescribeAnimal(IAnimal animal)
{
Console.WriteLine("My name is {0}, I am a {1}", animal.WhatIsMyName, animal.WhatAmI);
}
static void Main(string[] args)
{
Dog mydog = new Dog("Dog", "Spot");
Cat mycat = new Cat("Cat", "Felix");
DescribeAnimal(mydog);
DescribeAnimal(mycat);
Console.ReadKey();
}
}
}
|
|
|
|
|
You can add these changes:
public abstract class Animal : IAnimal
{
public Animal(string WhatAmI, string WhatIsMyName)
{
_WhatAmI = WhatAmI;
_WhatIsMyName = WhatIsMyName;
}
....
public class Cat : Animal
{
public Cat(string WhatIsMyName) : base ("Cat",WhatIsMyName)
{
}
}
Although, I would have used an abstract method in animal called GetDisplayName which would be overridden in the subclasses..
modified on Saturday, May 24, 2008 5:17 AM
|
|
|
|
|
So something like this?
namespace IT274_U2
{
public interface IAnimal
{
string WhatAmI { get; }
string WhatIsMyName { get; }
}
public abstract class Animal : IAnimal
{
private string _WhatAmI;
private string _WhatIsMyName;
public Animal(string WhatAmI, string WhatIsMyName)
{
_WhatAmI = WhatAmI;
_WhatIsMyName = WhatIsMyName;
}
public string WhatAmI
{
get
{
return _WhatAmI;
}
set
{
_WhatAmI = value;
}
}
public string WhatIsMyName
{
get
{
return _WhatIsMyName;
}
set
{
_WhatIsMyName = value;
}
}
}
public class Cat : Animal
{
public Cat(string WhatAmI, string WhatIsMyName) : base ("Cat",WhatIsMyName)
{
}
}
public class Dog : Animal
{
public Dog(string WhatAmI, string WhatIsMyName) : base("Dog", WhatIsMyName)
{
}
}
public class TesterClass
{
static void DescribeAnimal(IAnimal animal)
{
Console.WriteLine("My name is {0}, I am a {1}", animal.WhatIsMyName, animal.WhatAmI);
}
static void Main(string[] args)
{
Dog mydog = new Dog("Dog", "Spot");
Cat mycat = new Cat("Cat", "Felix");
DescribeAnimal(mydog);
DescribeAnimal(mycat);
Console.ReadKey();
}
}
}
Ok It works, but I do not really understand where base() comes from. Now how does this work even though the methods Dog() and Cat() have nothing in them?!?
|
|
|
|
|
Ok I am been deleting things and looking at the errors it throws to try to understand this better. So when you use BASE it derives from the class that the class it is in derives from right?
So BASE is passing two arguments to public class Animal().
Now my question is, when you do this you have it setting the string _WhatAmI to WhatAmI(which was the constructor in Animal that base("Cat", WhatIsMyName) sent to it. See you still have to implement WhatAmI and WhatIsMyName as public strings so it will not throw an error. You have to implement them because they are in the Interface right?
so:
public string WhatAmI
{
get
{
return _WhatAmI
}
}
now that is setting _WhatAmI to. So now we have two areas in the coding that sets _WhatAmI, correct? No wait.. that is RETURNING the value of _WhatAmI to the string WhatAmI from the Interface... Let me know if I am wrong so far. So we are setting the private strings value in the method Animal(). Then we are creating public strings so it implements the Interface class. Then in those public strings we are setting the values in the Interface class. That Is why public string WhatAmI(get;) is in the interface. Because when you pass them to the Interface class it has to GET those strings you are passing.
So since we have Cat(string WhatAmI, string WhatIsMyName) ... which has to be there because you have to have it take 2 constructors the code : base("Cat", WhatIsMyNAme) is passing it directly from the method Cat() to the method Animal() since base is the class that Cat() derives from.
I hope I get got that right because if I did Im starting to get a much better understanding!!
|
|
|
|
|
Sorry about my last post I forgot to put the /pre in and it screwed everything up!
Ok I am been deleting things and looking at the errors it throws to try to understand this better. So when you use BASE it derives from the class that the class it is in derives from right?
So BASE is passing two arguments to public class Animal().
Now my question is, when you do this you have it setting the string _WhatAmI to WhatAmI(which was the constructor in Animal that base("Cat", WhatIsMyName) sent to it. See you still have to implement WhatAmI and WhatIsMyName as public strings so it will not throw an error. You have to implement them because they are in the Interface right?
so:
public string WhatAmI
{get
{
return _WhatAmI
}
}
now that is setting _WhatAmI to. So now we have two areas in the coding that sets _WhatAmI, correct? No wait.. that is RETURNING the value of _WhatAmI to the string WhatAmI from the Interface... Let me know if I am wrong so far. So we are setting the private strings value in the method Animal(). Then we are creating public strings so it implements the Interface class.
Then in those public strings we are setting the values in the Interface class. That Is why public string WhatAmI(get is in the interface. Because when you pass them to the Interface class it has to GET those strings you are passing.
So since we have Cat(string WhatAmI, string WhatIsMyName) ... which has to be there because you have to have it take 2 constructors the code : base("Cat", WhatIsMyNAme) is passing it directly from the method Cat() to the method Animal() since base is the class that Cat() derives from.
I hope I get got that right because if I did Im starting to get a much better understanding!!
|
|
|
|
|
Jacob Dixon wrote: My professor is not helping out very much
Some times that's the best kind of help.
Animal, Dog, and Cat will need constructors (as I think you know by now).
I wouldn't bother storing the WhatAmI, but instead access the name of the type, otherwise you can get:
Dog mydog = new Dog("Tiger", "Spot"); , maybe just do a sanity check on the passed value, but it's a poor design.
As it's homework I suggest the use of an automatic property for WhatIsMyName.
|
|
|
|
|
yea he didn't like how I did it. He is saying the strings in Animal should be private not protected. He is saying I should not have access to those directly but through properties.
|
|
|
|
|
Hi all,
I have a application that receives a data buffer from TCP\IP, and save the buffer with the corresponding timestamp the event ocurred.
Now I need to simulate the TCP\IP data arriving just by reading the log, but using the timestamp information, to receive the events along with the same timings I would if using the original channel.
This code isn't hard but it would be good to get something ready for use. I'm sure this kind of requirement is not new.
Any tips ?
Thanks !
|
|
|
|
|
hi
in my app, i fill dataTable with some records include this columns :
DataColumn dcSpName = new DataColumn("SpName");
DataColumn dcParameterName = new DataColumn("ParameterName");
DataColumn dcSystemType = new DataColumn("SystemType");
DataColumn dcLength = new DataColumn("Length");
DataColumn dcIsOutputParameter = new DataColumn("IsOutputParameter");
as u can see, i want to load all stored procedures in my database with all parametersInfo, therefore, each new parameter for single sp cause new record insert into my dataTable object.
now, i want to remove duplicates rows from my dataTable objects to remain unique storedProcedures in my dataTable object, but how to remove them ?
thanks
|
|
|
|
|