|
Hello
Before all lets first admit something.. Whatever the design all code written in any language will eventually be translated to machine code, no matter what language you use even C#. In case of C# some details are different concerning JIT -Just In Time- compilation.
Anyway, OO design has many concepts including Encapsulation, ie. stuffing everything into classes instead of throwing them everywhere as global variables and funcions. In memory everything get mixed up -well, not exactly -, and when you make a memory dump in hex, you don't see bounadries between bits, and bytes!!
So, OOP is just a way of high level programming to isolate you code into smaller segments where you can debug, and understand easily. Some sort of organizing you code no more!! The end result in memory is almost the same.
Regarding your question about main method:
sawerr wrote: In c++ main() is not in a class.Main() is called by OS
Yes! In C++ main function is not in any class. Main is called the Entry point. So it's where the OS knows where to start you application. OS enters your application from here. The entry point's name and address in the code is put in the PE header, which is a small segment at the very beginning of the EXE file.
sawerr wrote: Also C# designers says :C# is truely oo language
With all respect... CRAP!! Nothing is perfect! Forgive if I don't express more about this point!
sawerr wrote: But Main() can not be a part of a class
Who said so?? You just said yourself main method must be a part of any of your programs class.. Typically it's present in the Program class of your project in Program.cs file.
sawerr wrote: here main() is not member of exercise class
It's a private static member. Yes it's a member. but it's static so that it's not specific to an object, rather it's shared between all objects of the same class. Private because we don't want it to be called outside the class or inherited to any other class
sawerr wrote: Also is main() must be in a class for a language that want to be truely oo?
Well, depends on the designers' point of view. Actually perfect OOism doesn't exist in my opinion!! It doesn't matter if ain is a part of a class or not, as long as you understand the structure your code will take in the memory. They prefer it would be encapsulated in a class. For me.. I don't care. Do you? Does it make a difference?
sawerr wrote: What is the advantage/magic behind this
Nothing!!
sawerr wrote: I think this is wrong design and confusing thing
Why?? There must be an entry point for your application. Inside a class, outside a class, doesn't really matters. In C# they try to be as OO as possible, so they put it in a class. In the typical project it's put in the only non-UI class, ie. the program class. Sounds right to me!! In here you can make a pre-Form initialization code. For example if you want only one instance to run of your program. You can check if other instances are running in the main method of Program class, before showing any forms..
Q: Can I put the main method in another class other than the Progam class.
A: Sure! Why not?
Regards
|
|
|
|
|
|
Yes, this is an "irregularity" in C# and Java. Main() is in a class but it is not an instance method.
It doesn't have to be like this though. In Eiffel all methods are instance methods and you specify a start-up class rather than a static main method. A bit analogous to the way you specify a startup page in an ASP.NET app.
Kevin
|
|
|
|
|
I'm working on CRX14 communication. I have this dll that was written in c++ language ("CRX14USBDLL.dll").
The c++ dll function is:
Get_HID_StringDescriptors(char VendorN[100], char ProductN[100], char SerialN[100])
Now in my c# code:
I dllimported this dll as:
[DllImport("CRX14USB.dll") public static extern void Get_HID_StringDescriptors(char[] VendorN, char[] ProductN, char[] SerialN);
now with the variable declarations:
char[] VendorN = new char[100];
char[] ProductN = new char[100];
char[] SerialN = new char[100];
Now to call the dll function:
Get_HID_StringDescriptors(VendorN, ProductN, SerialN);
to display the variable in message box:
messText = VendorN + ", " + ProductN.ToString() + ", " + SerialN.ToString();
MessageBox.Show(messText);
Am i doing anything wrong here? Anyone can help?
|
|
|
|
|
Hello
Blubbo wrote: Am i doing anything wrong here? Anyone can help?
You didn't specify what error do you get of this code?
Regards
|
|
|
|
|
Try passing a string into the native method, rather than a char[]. Also, if the native method modifies the string in anyway, you'll need to pass in a StringBuilder
|
|
|
|
|
Try passing a string into the native method, rather than a char[]. Also, if the native method modifies the string in anyway, you'll need to pass in a StringBuilder instead of a string or char[].
|
|
|
|
|
Hi!
I'm assuming little problems instancing a set of sprites from a single
AnimatedSprite class using SDLdotNet with C# 2005.
let's check my Generate() function in the Stone Class:
<br />
<br />
AnimatedSprite asMySprite;<br />
<br />
public void Generate(AnimatedSprite asfOrigin)<br />
{<br />
int iRND = Random.Next(0, 5);<br />
asMySprite = new AnimatedSprite();<br />
asMySprite = asfOrigin;<br />
<br />
switch(iRND)<br />
{<br />
case 0:<br />
asMySprite.CurrentAnimation = "aaa";<br />
case 1:<br />
.<br />
.<br />
.<br />
<br />
So now my problem is, that after calling the Generate()
function, if I change some properties of the asfOrigin
structure, they are also changed in my asMySprite
structure, regardless to the fact that I am instanciating
asMySprite with the new keyword prior to copying it's
changes.
What am I doing wrong???
Thanks for help in advance,
Chris
|
|
|
|
|
Hi Chris.
Within the line asMySprite = asfOrigin; you are assigning a reference of asfOrigin to asMySprite. So far the objects asMySprite and asfOrigin represent the same object, but with two different pointers to it. Calling new in the line above has no effects, because you are overwriting the l-value (reference) of asMySprite in the next line.
Maybe you should implement a clone method for AnimatedSprites, where you copy the value of asfOrigin to an assigned object (but pay attention to references).
Example:
public class AnimatedSprite {
.
.
public AnimatedSprite CopyThis(AnimatedSprite asfMyNewSprite){
asfMyNewSprite.Attribute1 = this.Attribute1;
.
.
.
}
.
}
Hope this helps you.
Regards
Sebastian
|
|
|
|
|
asMySprite = new AnimatedSprite();
asMySprite = asfOrigin; <- Problem here
Classes are reference objects, your are saying that asfOrigin and asMySprint are referencing the same memory location at this point.
Object.ReferenceEquals(asMySprint, asfOrigin) = true
You can override the Equal operation or derive from IClonable to make a copy of the object's data to get it to behave as you are expecting.
only two letters away from being an asset
|
|
|
|
|
lets say it like microsoft would: "this is not a bug, it's a feature!"
you just were introduced to the worl of object oriented programming.
the problem which has occoured is not really a problem.
the object passed to the function will be passed as a reference.
that means you will just permit its address and the function will access
the original object.
As you have just noticed there is no new object.
But stop, there is. You wrote:
<br />
asMySprite = new AdnimatedSprite();<br />
this line means you're allocating some memory on the heap for a new instance of the class animated sprite. the address of the beginning of this memory (i guess in .net its a bit different...) is assigned to the asMySprite variable. In the next line you write:
<br />
asMySprite = asfOrigin;<br />
Now you assign the address of the ORIGINAL object to the variable. this means you "overwrote" the variable and it isn't pointing to the new object anymore.
Thats why this error occurs.
To avoid this situation, you should make yourself familiar with references and "deep copies" of objects.
There is no general solution for your problem since the circumstances are different for each class...
Good luck,
mik
|
|
|
|
|
I now copy each Attribute of one class to the other and now
it works. Thanks for your help!
Greetz,
Chris
|
|
|
|
|
Hi Chris
I guess that by doing this you want to get the same values from the original object to a new object
and change its property.
well, all that says on the preveius nodes are correct.
but if i understend you correctly then to implement what you need is
you should create a contractore for your object "AnimatedSprite " which
get the values as you want
like:(in the AnimatedSprite Class)
public AnimatedSprite (string currentAnimation,string property2, string property3....)
{
this.CurrentAnimation=currentAnimation;
this.Property1= property1;
this.Property2= property2;
}
then in your Generate function
asMySprite = new AnimatedSprite(newCurrentAnimation,asfOrigin.prop2,asfOrigin.prop3);
this way you create a new instance of AnimatedSprite with the values that you want
Guy
|
|
|
|
|
Hi Everybody,
The List Objects in Excel 2003 grow row-wise automatically as and when a user enters some value in the row next to the last list row.
Is there any way to limit this behaviour of the list object.
Hope to hear from you people at the earliest,
Thanks in Advance,
Karthick
|
|
|
|
|
Hello...
I don't want to load my application more than once. That's why, I'm using GetProcessesByName.
If length of process array more than 1, that means exit, if only 1, then OK.
But someone told me that I must use Singleton.
What do you mean about that ? Is Singleton the right way ?
|
|
|
|
|
|
hi.
how i can include dotnet framework in my project setup application?
thanks.
|
|
|
|
|
|
Hello,
how can I safely call a method from another thread? For instance, a method that belongs to a progressbar control on my form, from a backgroundworker thread.
I've tried using events, lock, volatile but nothing worked. I always get the InvalidOperationException (Cross-thread operation not valid).
I am trying to execute the PerformStep() method of the progress bar on the main form every time a certain progress is made in the backgroundworker.
It's quite weird that I solved a similar problem with updating the status bar on the main form by using events, but that was made by assinging a string to the .Text property. Seems like in a cross-thread operation, changing properties is ok, but calling a method is not.
I know there's another way to report progress with backgroundworker, namely via the Backgroundworker.ProgressChanged event, but my question is somewhat more general: how to call a method from another thread safely?
Thanks,
Michal
|
|
|
|
|
You can use the Invoke method of the control to safely execute a method on the control's thread. Generally it is not safe to do any GUI control manipulation on a non-GUI thread, you need to marshall those calls across to the GUI thread using Invoke.
--------------------------------------------------
|
|
|
|
|
Thank you very much!
Invoke() method and one delegate solved the problem.
It's great there are people like you who are willing to help.
Thanks,
Michal
|
|
|
|
|
I just have 2 questions :
1. how to override a api function ? (i mean the technique)
2.how to do that if i use c#
Please help me !
Thanks
hoang van tien
|
|
|
|
|
hoangvantien wrote: 1. how to override a api function ?
To be able to do this, the class containing the function you're interested in must have 2 requirements: the class cannot be sealed, and the function must be virtual.
If both of those conditions are met, you can inherit a class from the class containing the function you're interested in, then override the method in that class.
public class ClassYouAreInterestedIn
{
public virtual void DoSomething() { ... }
}
public class MyOverride : ClassYouAreInterestedIn
{
public override DoSomething() { ... }
}
|
|
|
|
|
As API is a quite broad term (and often abused), the answer may well depend on the context of your API:
1) If API is a C API or like, there will be no overriding, as overriding only applies to OO programming. Function overloading will make sense in this case. But see 2).
2) If API is a library you load via Platform Invoke, you could only override the invoked method in your C# wrapper, not the original one. Thus, there will be no direct overriding.
3) If API is a .NET assembly (DLL), lets say, written in managed C++, you can extend the base class and override its methods if the class is derivable, thanks to the cross-language compatibility of .Net Framework.
4) If...
Best,
Jun
|
|
|
|
|
I am searching for a customized treeview control which has the following functionalities:
1) Word wrap for the nodes.. since i want to avoid the horizontal bars
2) For scrolling i am using two buttons.. but i m not able to bind the button click event with the scroll event of the treeview control
3) Set background image for the treeview and also set images for each node.
I m using VS 2005 and .NET framework 2.0
If anybody has developed such control, kindly send me the source code.
Any help will be appreciated
Thanks
A.K
|
|
|
|
|