|
I'm testing this code and all I get is a freaking unhandled FormatException, I don't know why but it tries to parse an int from the string I send as parameter. Why is this happening?
<br />
PerformanceCounter pc = new PerformanceCounter( "Memory", "Available MBytes" );<br />
try<br />
{<br />
Console.WriteLine( "Available RAM: " + pc.NextValue().ToString() + "MB" );<br />
}<br />
catch (Exception e)<br />
{<br />
Console.WriteLine(e.ToString());<br />
finally<br />
{<br />
pc.Close();<br />
}<br />
The exception: System.FormatException was unhandled.
Message="Input string was not in a correct format."
at System.Int32.Parse(String s, IFormatProvider provider)
at System.Diagnostics.PerformanceCounterLib.GetStringTable(Boolean isHelp)
at System.Diagnostics.PerformanceCounterLib.get_NameTable()
at System.Diagnostics.PerformanceCounterLib.get_CategoryTable()
at System.Diagnostics.PerformanceCounterLib.CounterExists(String category, String counter, Boolean& categoryExists)
Thankful for any help. Is this class supposed to be used in another fashion since 2.0?
|
|
|
|
|
hi
i tried to insert to listview for each row a new image when i try to do it i see always the same image
what do i need to do?
thanks
have a nice day
|
|
|
|
|
How do I do voice chat.
How to convert voice into bytes.
Any Idea abt this .Please send me.
|
|
|
|
|
If you have got some solution for Voice Chat. Please also let me know how to do that. How are you capturing sound from Mic? if you are ready to convert it to byts? Please also help me if you get some clue. Thanks in advance.
Best Regards,
Rizwan Ahmed
|
|
|
|
|
Do one thing. Download VaxVoIP SDK from net. I think google search will help you to do that. VoIP is the better way of communication through Voic and text
.
Cheers
|
|
|
|
|
I have to view all drives,directories,files of a remote machine in to my
local machine.How can I do that in use of Tcp socket.
Deepthi
|
|
|
|
|
In my point of view, Remoting will be the simplest way to do that.
You can find a lot of articles on coderproject on remoting.
The idea is:
1) you'll write a remotable object (dll) with some function who gets this information from the local computer and returns this information to its caller. This information must be in serailizable form. you can use XML or even a string as a return type. All you need is to re calculalte you information from that returned value back.
2) A Server will expose this object to be called by the clients on a specific URI.
3) Client will use a proxy of that remotable object and connect to the server by registering a channel and Call that method remotely just like its a local function of it, get the required information.
I have tried to give you some idea. Please read some article about remoting. You'll achieve your goal within 30 minutes for sure after understanding remoting.
Best Regards,
Rizwan
|
|
|
|
|
Hi ...
I'm having trouble setting the values of the array in my class.
I tried this ... and i can set/get "x.name" but pgm crashes with an error message that says i do not have an instance of the array item when i try to set "x.number[1]".
namespace WindowsApplication1
{
public partial class Form1 : Form
{
class myClass
{
// fields
private string _name;
private double[] _number;
// properties
public string name
{
get { return _name; }
set { _name = value; }
}
public double[] number;
public double this[int index]
{
get { return _number[index]; }
set { _number[index] = value; }
}
// Default constructor:
public myClass()
{
name = "";
double[] number = new double[5];
number[0] = 0;
number[1] = 0;
number[2] = 0;
number[3] = 0;
number[4] = 0;
}
// Clear Numbers
public void ClearNumbers()
{
double[] number = new double[5];
number[0] = 0;
number[1] = 0;
number[2] = 0;
number[3] = 0;
number[4] = 0;
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
myClass x = new myClass();
x.name = "Charlie";
x.number[1] = 123.45;
}
}
}
My program works on x.name = "Charlie";
My program fails on x.number[1] = 123.45;
Please advise on how to fix my class definition to accomodate arrays.
Thank you.
-- modified at 10:17 Saturday 25th March, 2006
|
|
|
|
|
The code in the constructor is not even possible to compile. Why don't you show the code that you really are using?
I assume that the code in the constructor looks like the code in the ClearNumbers method, as that at least compiles...
You have two array references in the class, _number and number. You never assign anything to any of them, so of course you get an error message when you try to use any of them. If you look at the task list after compiling, you will see that the compiler has given you very informative warnings about this.
---
b { font-weight: normal; }
|
|
|
|
|
Sorry ... i have corrected the original post.
i should have just copy/pasted the whole original .. i did not actually save that much space when i copied just part of the problem ... and i introduced an error.
Thank you for pointing that out.
As you can tell ... i am a newbie at class definitions. I have no idea why the underscore character precedes the field names and then (if needed at all) why it is not used in EVERY reference to the field.
But not having a knowledgeable mentor ... i am subject to the problems associated with "mimicking" what i have seen in other class definitions.
I think u get the idea of what i am trying to accomplsh. Please suggest code change to the class so the button code works.
Thanks.
|
|
|
|
|
You have two arrays, like Guffa said, number and _number and you dont assign anything to either of them. The fact that they have the same name, give or take an underscore, means nothing, they are completely different variables that are in no way related to each other.
Your code crashes on x.number[1] because you havent initialised number to anything, and so it is currently null . So trying to access the second value of it will crash because there is no second element. Try the following code, is should work...
class myClass
{
private string _name;
private double[] _number = new double[5];
public string name
{
get { return _name; }
set { _name = value; }
}
public double[] number
{
get { return _number; }
set { _number = value; }
}
public double this[int index]
{
get { return _number[index]; }
set { _number[index] = value; }
}
public myClass()
{
name = "";
_number[0] = 0;
_number[1] = 0;
_number[2] = 0;
_number[3] = 0;
_number[4] = 0;
}
public void ClearNumbers()
{
_number[0] = 0;
_number[1] = 0;
_number[2] = 0;
_number[3] = 0;
_number[4] = 0;
}
} Hope that helps
Cheers,
Will H
|
|
|
|
|
Thank you so VERY much, Will ! Your suggestions work great!
I still do not understand the use of "this" in the code block ...
public double this[int index]
{
get { return _number[index]; }
set { _number[index] = value; }
}
... but for the time being, until i get that understanding, i can mimic what u showed me for future class definitions.
Your help is much appreciated!
|
|
|
|
|
That code block is there so that you can access myClass as though it was an array itself. It means that if you create an instance of myClass like so
myClass foo = new myClass(); then you can access your _number array in two ways. Like this...
double firstElement = foo.number[0]; and also like this...
double firstElement = foo[0]; The last way is only allowed because of the 'public double this[int index] ' accessor.
Glad I could help
Cheers,
Will H
|
|
|
|
|
Hey guys, is it possible to Dial a Number Using C# and be able to speak with the other person, using C#.
I'm writting a PhoneBook application i want to be a ble to search a number an dbe able to dial it.
By the way i want to have a help for my project, I haven't done such thing before, what's the best way fo doing so ?
I'd be grateful
|
|
|
|
|
How could i select a single speaker to play a sound with DirectSound?
I've a 5.1 soundcard which is configured as sorround sound, so that i can use the 6 outputs. This card appears in the system as one device (i have another 5.1 card and, with special drivers, it appears as 3 stereo devices, so it s easier to use, but i cannot use these drivers on the first card) and ive seen an application which can play a sound to a single speaker, so i should be able to do it too.
Ive thought about playing the sound as a 3D sound and selecting its position, but i dont think it s a good idea.
Any idea? Thx
|
|
|
|
|
hello all in codeproject,
i am new to the programming field and i would like to know more about how to use constructors and why do we use them regarding the idea that we can initialize our variables in any section without using constructors.
thank you for your concern
abdelhameed81@yahoo.com
abdelhameed
|
|
|
|
|
abdelhameed81 wrote: how to use constructors
See the program class to see how to use constructors
public class A
{
private string myText;
public A(string someText)
{
this.myText = someText;
}
public void WriteMyText()
{
Console.WriteLine(someText);
}
}
public class Program
{
public static void Main()
{
A a = new A("Hello World");
a.WriteMyText();
}
}
abdelhameed81 wrote: why do we use them regarding the idea that we can initialize our variables in any section without using constructors.
Because it is good practice to initialise the fields to something sensible. The CLR will initialise the fields to default values if you don't set them. e.g. an int will be set to 0 , a string to "" and so on. But they may not be sensible for your application.
In objects that are immutable there is no opportunity to set the fields after the constructor has setup the object. The very nature of an immutable object is that it does not change. So it MUST set the class fields at construction. For example the string class is immutable, you cannot change a string object, you can only create new string objects.
Sometimes you may have a situation where a field is a lazy lookup because it isn't used often and it takes a long time to retrieve the value. In that case it would be initialised to null (if it is a reference type) and the getter property would do the lookup and cache the value in the field when it has been retrieved.
ColinMackay.net
Scottish Developers are looking for speakers for user group sessions over the next few months. Do you want to know more?
|
|
|
|
|
Colin Angus Mackay wrote: The CLR will initialise the fields to default values if you don't set them. e.g. an int will be set to 0, a string to "" and so on.
A slight correction, just to avoid misunderstandings:
A string will be initialised to null, not to an empty string.
---
b { font-weight: normal; }
|
|
|
|
|
A construtor is always used to create an object. If you don't declare a constructor for a class, an empty constructor is created.
As there always is a constructor, it's a sensible place to initialize the data in the object. That way it's impossible to forget to initialize it.
---
b { font-weight: normal; }
|
|
|
|
|
hi,
i am using TAPI3 for outgoing call, i make call but the problem is how do i know whether otherend has picked up the phone or not because when phone is picked up by someone i want to play audio.
|
|
|
|
|
I'm trying to do the same thing from the scartch can you give me a sample code or something like that to call a number in a C# from ...
Thanks
|
|
|
|
|
I also want to do it. Please guide me or give some code for demonstration purposes. I'll be so thankful to you.
Best Regards,
Rizwan
|
|
|
|
|
i am in a project containing a part that give someone a call
will you give me a sample code too in C#
|
|
|
|
|
I don't hav such code ...
what language are you using ?
Mr.K
|
|
|
|
|
Hi,
Can We detect Sql Servers on Network using c#
Like when we reister new conection sql server it shows the list of all server in the network.
This is same i need to do in my c# product installer.
Thanx & Regards
Anuj Kamthan
Software Developer
Solversa Technologies,
Pune - 411007, India.
http://www.solversa.com
|
|
|
|