|
To use pointers in C# you need to create an unsafe class, or an unsafe block. There's really no reason to do so, all classes are passed by ref in C# anyhow.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
But what about value types?
ref and out keywords?
Regards,
Arun Kumar.A
|
|
|
|
|
Have a look at http://www.codeproject.com/dotnet/pointers.asp
|
|
|
|
|
hi i am currently trying to call a function of another class.
(i am not trying to copy the function over i am trying to calling directly to it)
something like:
class main
{
cow cow1= new cow();
dog dog1 = new dog();
}
i am trying to call for lets say a fucntion called moo from the dog's class fucntion within the dog class.
class dog
{
void woof()
{
moo();
}
}
if this was c++ i would have pass the main's instance variable over to both the cow and dog class upon creation but i have no idea how to do this in c# pls help
|
|
|
|
|
There are numerours ways of doing this - you could create a constructor of the Dog class which takes a Cow variable as a parameter - store this within the Dog class and then use that paremeter within the Woof function to call the Moo function.
i.e.
<br />
Dog(Cow cCow)<br />
{<br />
m_Cow = Cow;<br />
}<br />
<br />
void Woof()<br />
{<br />
m_Cow.Moo();<br />
}<br />
Alternativley make the Moo function static and then you call it like this
<br />
void Woof()<br />
{<br />
Cow.Moo();<br />
}<br />
There's probably lots of other ways but those might be the simplest.......
|
|
|
|
|
The best way to do this sort of thing in C# is with delegates ( nicely wrapped function pointers )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
how about if i need to call back?
like
class rat()
{
cow cow1=new cow()
void moo()
{
}
}
what if i need to call the moo function from inside the cow instance?(one of the function inside cow)
|
|
|
|
|
i tried the delegate however it keep giving me error can help me chk?
class cow<br />
{<br />
delegate void Delegateking();<br />
<br />
moo hihi;<br />
cow()<br />
{<br />
<br />
Delegateking lala = new Delegateking(this.setter);<br />
hihi = new moo(lala);<br />
}<br />
public void setter()<br />
{<br />
Console.WriteLine("power");<br />
}<br />
}<br />
<br />
class moo<br />
{<br />
string data;<br />
delegate void Delegateking();<br />
<br />
public void set(Delegateking lol)<br />
{<br />
lol();<br />
}<br />
}
|
|
|
|
|
Hi at all,
on my Windows Form i have some Controls whose properties need to be changed by another class that is not derived from the Forms class. How can this be achieved? (is it possible at all?)
For example:
public class Form : System.Windows.Forms.Form
{
...
public System.Windows.Forms.ToolStripStatusLabel tlStrpStatusLblState;
...
}
public class PB_OPC
{
public static void OnServerShutdown(string reason)
{
Form.tlStrpStatusLblState.Text = "OPC Server Not Connected";
}
}
I originally thought that would be possible by changing the "modifiers" Attribute to "Public", but it didn't help.
Thanks for your efforts
|
|
|
|
|
try it as "public static",it will work well.
but it's not the best sovlution.
|
|
|
|
|
Hi,
thanks a lot, it really did help, but i truly agree that this isn't the best solution.
What about the programming style in OOP? Is it a bad habit to access a control from a separate class? I just wondered if there's an alternative.
|
|
|
|
|
|
Thanks for the link.
|
|
|
|
|
Yes, I thought a beginner like you can profit from that article!
;)
|
|
|
|
|
Yes, I sure did.
|
|
|
|
|
Hi guys iam new to dis i think so every will help me
hear's my Question
In c# multiple main() is possible and i have problem dat i cannot compile & run it prompt,but i can do it in VS.5.
chella
|
|
|
|
|
In C# if u use IDE the mutilple Main() is not possible. But u can use multiple Main() with different return type. and u have to comiple it with "csc" command line compiler giving appropiate option. Through VS.Net IDE it will give error
|
|
|
|
|
HI
How can I work with text files in C# .net? For example I want to open a text file, read portion from the file and then display that portion on the pop-up message.
|
|
|
|
|
that should not take much code
first use a System.IO.FileSteam(fileName, FileMode, FileAccess, FileShare)
then pass this stream into a System.IO.StreamReader
then use streamReader.ReadLine() to return each line as a String, or there are other options in the stream reader to read from certain offsets, and certain lengths, then whatever data you capture this way can be passed to the MessageBox.Show(message, boxTitle, Buttons, Icon)
|
|
|
|
|
System.File.ReadAllLines("c:\text.log");
will give you a string array, ReadAllText will give a single string.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
That will teach me to read documentationin advance, not just when I'm stuck. How many times in my code do I open a file, called ReadToEnd, or iterate through the file populating my array manually...
Cheers (again!) Christian for that one.
|
|
|
|
|
hello, this is my first question on The Code Project, I am writing a program that can record worship services for my church, then later burn the recorded tracks. I am using XPBurn to burn the CD audio, but my problem is, alot of our tracks flow from one right into the other, so therefore I need to remove the 2 second audio gap, does anyone know a way to do this, or have any other suggestions. I am also not married to the idea of XPBurn, it just seemed the easiest. Also i would like to be able to dynamically set the volume name of the cd before it burns. Both AudioGapSize and VolumeName properties are read only and cannot be set in the XPBurnCD class
thanks in advance for any help anyone can offer
|
|
|
|
|
I need some help... I have a method that I want to execute at a specific time.
For example, every 3PM it will execute this method.
Any suggestions or help on this. I don't think it would be that difficult... I was thinking I could just capture the system time, on form load. Then while (system time == 3PM) execute method.
Not sure if that would work
Let me know asap!
Thanks guys
|
|
|
|
|
i think that use the Timer will match your needs.
|
|
|
|
|
yeah - i'm kind of figuring out how that works.
I created an action for the timer tick below:
<br />
private void tmrClock_Tick(object sender, EventArgs e)<br />
{<br />
if( sender == tmrClock )<br />
{<br />
Invalidate();<br />
}<br />
On Form load, I have the timer interval set to a few thousand milliseconds. Then I start the timer. This is all I have so far.
I'm guessing my method goes in the tmrClock_Tick?
Is that right?
|
|
|
|