|
|
Do you, or is it bad practice to do this sort of thing: Class A { Class B {} } ? I have never seen any of the book examples show that you ever would do this.
Here is the example I was working on.... the first class Tester code (not commented out) does not compile (error: The name Temperature does not exist in the current context). But below the commented out class Tester code will work because I removed the Values class. Is there a way to get it to work without removing the Values class. ( Please keep in mind, some of this might not be a very practicle example.... i.e. it really does not make sense to have the Values class in the first place!)
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace EnumFreezingInRun
{
// this gives error "The name Temperature does not exist in the current context"
class Tester
{
class Values
{
enum Temperatures
{
WickedCold = 0,
FreezingPoint = 32,
}
}
public void Run()
{
Console.WriteLine("Freezing is: {0}", (int)Temperatures.FreezingPoint);
Console.WriteLine("Wicked cold is: {0}", Temperatures.WickedCold);
}
static void Main()
{
Tester t = new Tester();
t.Run();
}
}
// This does work!
//class Tester
//{
// enum Temperatures
// {
// WickedCold = 0,
// FreezingPoint = 32,
// }
// public void Run()
// {
// Console.WriteLine("Freezing is: {0}", (int)Temperatures.FreezingPoint);
// Console.WriteLine("Wicked cold is: {0}", Temperatures.WickedCold);
// }
// static void Main()
// {
// Tester t = new Tester();
// t.Run();
// }
//}
}
|
|
|
|
|
LuluSailor wrote: Do you, or is it bad practice to do this sort of thing: Class A { Class B {} } ?
I wouldn't say it was bad practice. Only that there are a limit number of situations that would warrant this.
The only one I can think of is to have the enumerator (a class deriving from IEnumerator) as an inner class of the one that it enumerates (which will normally implement IEnumerable).
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
Thank-you for taking the time to answer my question Colin. It did seem that this is not too common, since I did not see it done in examples (class A {class B{}} )
So is there another way to get the code to work, other than remove the pluck out (delete) the Value class from the code? I am just curious how I would get the Temperatures to become available/ or in context without removing the class.
Although - my main concern you have answered, which is how common it would be to define a class within a class. I am still not sure what I am really doing when I define a class within a class. But this might be a bit too advanced for me right now. For now - I will not do it (accidentally or otherwise)!
|
|
|
|
|
Another reason that you may want to define an inner class relies on how you will use B in class A{ class B{} } . If only A uses B and no other class should use B , then a private inner class would work well in that situation.
For example, if you write a class that acts as a binary tree that supports only adding, searching, and removing, then you may never need to expose the class that implements the node in that tree structure. Thus, you could have something like the following incomplete code snippet.
public class Tree
{
public Tree() {
public object Search( object obj ) {
public void Add( object obj ) {
public void Remove( object obj ) {
private class Node
{
public Node( object o ) {
}
}
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
A simple resolution:
using System;
using System.Collections;
using System.Text;
namespace EnumFreezingInRun
{
class Tester
{
class Values
{
public enum Temperatures
{
WickedCold = 0,
FreezingPoint = 32,
}
}
public void Run()
{
Console.WriteLine("Freezing is: {0}", (int)Values.Temperatures.FreezingPoint);
Console.WriteLine("Wicked cold is: {0}", Values.Temperatures.WickedCold);
}
static void Main()
{
Tester t = new Tester();
t.Run();
}
}
}
|
|
|
|
|
I am writing a library and a class that uses it, but somehow, when I change something in the library, after I run it and re-add it as reference, the class still uses old library, any idea?
I tried rebuilding/compiling still nothing.
I closed visual studio and opened back up after removing the reference still uses old library.
Added the library as a new solution to my project still uses old library
Deleted all files in the debug/release folders still uses old library
What am i doing wrong here?
Cant seem to figure this one out, "real headache"
Can someone help me?
Thanks
|
|
|
|
|
Perhaps the reference in the client class is pointing to a local copy of the library (and not the library's /bin instance)?
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Ok perhaps it is......
what do i do???
if it is not what do i do???
-- modified at 11:01 Saturday 28th January, 2006
Perhaps the reference in the client class is pointing to a local copy of the library (and not the library's /bin instance)?
How and where do i check to see if it is pointing to a local copy of the library???
Thanks for replying
|
|
|
|
|
Modify the reference (in your client project) to point to the dll in the library's /bin/Debug (and /bin/Release for the release configuration) folder. When you (re)build your client project, the latest versions of the appropriate DLLs will be copied (if necessary) from the library's folders into your client's.
Hope this helps!
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
I assume the class library is not part of the same solution? In that case, add a reference to the DLL, then right click on the reference in Solution Explorer, click Properties and set Copy Local to false.
If it's part of the same solution, then when adding the reference, add it from the Projects tab in the "Add Reference" dialog box.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
awesome!! got it to work thanks guys
|
|
|
|
|
I need to know if in C# language there's classes that allow me to acceses information from the hard disk.... or if there's an API for that... i'm a begginer in this..
El sammy
|
|
|
|
|
|
.NET Framework 2.0 has the DriveInfo class that you can use to get a list of drives and info about each of them.
--
Hello, I'm a signature virus. Copy me into your signature to help me spread.
|
|
|
|
|
hi, i need create appz for using/control modem v32 bis.
where i can read some manual about this.
thx.
Athlon 64 3500+, Gigabyte GA-K8NXP-9, 2x512 DDR400 Kingston, Inno3d 6200 PCIe, SS2 B2C2 v2.6, HDD := 450gb, Genius 56k int, NEC DVD-RW и мать его Суньмастер 550.
|
|
|
|
|
i want to make a setup project that creats a database to target machine
is there anybody who knows ??
|
|
|
|
|
isnt there anybody who knows how to do this? it is very important and urgent for me
|
|
|
|
|
Hi
Please let me to ask my problem from you.
I want to record user's sound. may be there are several codes to do this.
But I want that my program create blank wave file and then open Windows Sound Recorder that record sound on that blank file.
Openning Sound recorder is easy :
<br />
Using System.Diagnostics;<br />
Process.Start("sndrec32.exe");<br />
How can i create blank file and enforce Sound Recorder to use that file.
Please Help me
Thank You.
-- modified at 5:29 Saturday 28th January, 2006
|
|
|
|
|
Your only bet is finding command line parameters for sndrec32.exe to do that..
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hello Again.
NoBody helped me, But I found my answer myself and I want to share it with everbody.
<br />
using System.Diagnostics;<br />
using System.IO;<br />
Now use this :
<br />
Process.Start("sndrec32","C:\\File1001.wav") ;<br />
Or this :
(I Created new blank Wave File and enforced Sound Recorder to Play it
<br />
string strFilePath="C:\\" + "File1002" + ".wav" ;<br />
File.Create(strFilePath) ;<br />
ProcessStartInfo startInfo = new ProcessStartInfo("sndrec32.exe");<br />
startInfo.Arguments = strFilePath ;<br />
Process.Start(startInfo);<br />
Use it and enjoy!
-- modified at 5:18 Sunday 29th January, 2006
|
|
|
|
|
Hi,
Its giving me a Error like "Can't Open File c:\file001.wav"
I tried both methods of doing that... but both methods are showing me same error..
One more quest abt is how to Record the Sound.. ie process.Start(...) is responsible for opening soundRecord exe after that how to press "Record" button programmatically...
Send me ur suggesstions
|
|
|
|
|
You got problem beacause the file is not exist or its already open !
Use this :
<br />
string strFilePath = @"C:\" + "file1001" + ".wav" ; <br />
FileStream waveFile = File.Create(strFilePath) ;<br />
waveFile.Close() ;<br />
Process.Start("sndrec32",strFilePath) ;<br />
It worked on my system.
|
|
|
|
|
Hey everybody
I'm trying to write a program that will check if my disc-on-key is connected or not. I tried to use the "printer usb connected checker" article as an example, but it doesn't work. can anyone at least give me a small hint on how do I check if a disc-on-key has been connected?
I also thought of checking any changes in the number of drives, but I'm looking for a more elegant way.
Thanks Alot!!!!
|
|
|
|
|
Hi All !!! There are some Projects using NumericUpdown from NumericUpdown Screen without using arrows, moreover there is not any hidden layer too. cause should u set a number with 3 digit the 3.rd digit continous working. The thing I wonder is that is that a new control or a code. Can someone give me some clueas about it.I am really Puzzled. A .Net Vb Or C# code would be enough.
|
|
|
|