|
Is this the only point. Then y did they introduced a new term without one facility.
|
|
|
|
|
Remember that when a new class is defined, it can inherit from only one base class. There are no restrictions on the amount of interfaces that the class can support.
For example, consider the Arraylist Class from the .NET Framework. This class implements four different interfaces: IList, ICollection, IEnumerable, and ICloneable. By using interfaces instead of a base class, a coder may treat it as a list, a collection, an enumerable collection, and a cloneable object, whichever he sees fit.
As another example, consider two classes Amoeba and Dog. Say that Amoeba derives from Unicellular since it is so simple and that Dog derives from Mammal. Both creatures need to Eat(), but because they do so in fundamentally different ways it makes no sense to provide Eat() in a base class common to both. A much better solution would be for them to both implement IMustEat, which forces them to have an Eat() function. IMustEat (an interface) does not define how - or even if - an Eat() method works. All it says is that an Eat() method must exist.
Remember that if not explicitly specified, a class derives from System.Object. The Object Class is very elementary and provides almost no functionality. On the other hand, implementing an interface allows you to make contractual guarantees about your class.
Hope this helps!
|
|
|
|
|
Ok heres the scoop... I'm binding an arraylist of objects to a datagrid. I've got the data to show up by implementing the properties for my object. I've got my datagridtablestyles setup and working right. Things are going good... now I need to know how to add a new row. When I used a dataset with the datagrid there was always a "blank" line at the bottom you could just start typing in. I'm afriad that this was a implementation of the dataset and not the datagrid. So my question. How can I create that same functionality with my ArrayList of ojbects. Or what is my best method of adding new "rows" to my datagrid.
Thanks
Bryan
|
|
|
|
|
Is there a way I can retain the selected values by using checkboxes while navigating between pages in the datagid control?
For eg: If i check one row and i will go to next page of the grid if I come back i want to retain the checked valued with checkbox checked...
I am using normal paging....
|
|
|
|
|
|
Hello,
In a button click method I create an EventLog, set its EnableRaisingEvents property to true and attach an event handler for the EntryWritten event.
<br />
EventLog eventLog = new EventLog(cbEventLogs.Text,txtMachineName.Text);<br />
<br />
if(this.txtMachineName.Text == SystemInformation.ComputerName)<br />
{<br />
eventLog.EnableRaisingEvents = true;<br />
eventLog.EntryWritten += new EntryWrittenEventHandler(eventLog_EntryWritten);<br />
}<br />
My question is, how does the event still get fired when you exit the button click method where the event log was created? Doesn't the EventLog variable fall out of scope when the method exits, causing it to be garbage collected?
Thanx for the help,
-Flack
|
|
|
|
|
The garbage collector will only collect when there reference count goes down to 0. By subscribing eventLog_EntryWritten to the EntryWritten event you are creating a reference. That reference is enough to keep the eventLog alive. Even though you no longer hold a reference one does exist. To get the garbage collector to collect the EventLog unsubscribe the event before eventLog goes out of scope and you no longer have control of any of the references to it.
Karl Baum
CEO of KGB Technologies
Specializing in custom software development.
|
|
|
|
|
Hello,
I know this is the c# section, so my managed c++ code might be in the wrong place, but i know that the .net classes are the same in c++ or c# and all the code samples i have used are in c# and the logic is the same
I am trying to save an image stream into a .bmp file or a jpeg file. I an trying to use the .NET classes in the System::Drawing namespaces.
I have some code like the following
dev->Grab(buf);<br />
Byte b[] = new Byte[bufSize];<br />
MemoryStream *ms = new MemoryStream( b );<br />
for(int i=0; i{ <br />
b[i]=buf[i];<br />
}<br />
Bitmap *b = new Bitamp( ms ); <br />
b->Save(S"C:\\test.jpg", ImageFormat::Jpeg);
Every time i run the code the following line
Bitmap *b = new Bitamp( ms );
throws a ArgumentException:Invalid Parameter used exception.
Does any one Know Why, could it be that the Bitmap class understands that the stream is not a valid image yet because the stream only contains the row bytes... any help please...
|
|
|
|
|
Emiliano wrote:
could it be that the Bitmap class understands that the stream is not a valid image
I think you found the answer yourself :P
----------------------
Be proud. Be yourself.
|
|
|
|
|
thanks for your reply!! do you happen to know how to build the Bitmap file correctly in memory?
|
|
|
|
|
If I understand correctly, you're trying to save mpeg to jpeg? I don't think it's a really good idea... it would be much more complicated tahan juste capturing the stream. I'm not an expert in stream manipulation though... I may check this out if I got time but I'll need to know more what you wanna do.
----------------------
Be proud. Be yourself.
|
|
|
|
|
I'd like to either set the font of a headertext of one column of my datagrid (windows application) or put an image in it instead. How do I do that?
The thing is I'd like to have two special datagridboolcolumns in my datagrid (with many other standard ones): one is an 'accepted' column and the other one is a 'refused' column. Now instead of putting the strings "accepted" and "refused" in the column header, I'd like to keep it short and put a green checkmark and a red 'X' in the headers of those two columns... How can I do that?'
|
|
|
|
|
Hi!
Have a small question. Have added a couple of enum types to a project thinking it would be fast and easy. Altough I found a small disturbing thing that enoyed me. enum is an int as defult, so a declaration like:
private enum ints { zero, one, two };
generates like three int constants with values 0,1 and 2 ( at least in C and alike ). But C# does not treat ints.zero like an int, and I think that is kinda strange. What I would like to do is like:
int a = ints.zero;
But then VS compains about converting.
even if one declares the enum as:
private enum ints :int {zero, one, two };
it does not alow a simple: int a = ints.zero;
One have to do like: int a = (int)ints.zero;
Anyone who can explain why? I´m just confused why it is like that, its not like it is a problem, it just does not look so good.
/ M
|
|
|
|
|
You have to use a cast to convert enum to int.
int a = (int)ints.zero;
it's made there so that the compiler can catch type errors when using enums improperly.
Doing a cast, in my oppinion, is bad too because you're losing type-safety.
You can also convert from int to enum by:
ints v = (int)0;
|
|
|
|
|
Ok, can understand the type error thing, but still.. Since I declare the enum as a int ( through :int ) I thought I could use the enum fields as constant ints. It would give a nice looking code. And since the compiler knews it is an int I can´t really see the problem.
/ M
|
|
|
|
|
Mikke_x wrote:
And since the compiler knews it is an int I can´t really see the problem.
Yes, the compiler knows it is an int. And the compiler is forcing you to know it is an int also. If you have many developers on a team and one comes across your enum in use somewhere and they start using it willy-nilly then bad things can happen. So, the compiler forces the developer to declare that they explicitly want the enum value as an int because you are still losing type safety. This way, if yet another developer comes along later and looks at the code they will know exactly what is going on.
The above analogy can also apply if you are a lone developer also - many times I've gone back to code I've written a year or two back and I'm tracing though code line by line for something that at the time was quite natural. If I see an explicit cast I can understand things better and quicker than with an implicit cast. Implicit casts are by their nature hidden, there is nothing on the surface to indicate they go on.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
I would really stay away from converting Enums to ints.
One scenario it bit me in the ass was when I was saving Enum to a file by converting it to an int and then back.
The enum was like:
enum
{
One,
Two,
Three
...
}
and some other developer decided that they need OneAndHalf, so now the enum is:
enum
{
One,
OneAndHalf,
Two
}
now, when the object is loaded all Twos become OneAndHalf.
See why it's bad?
|
|
|
|
|
enums and casting them to ints are not "bad". The explicit cast requirement is to make sure you think about what you are doing. On a number of projects I've worked on I've converted enums to/from ints frequently so that in the C# code the developer will not use invalid values and when it is stored in an int field in SQL Server it can be stored as an integer.
Werdna wrote:
See why it's bad?
Your example is bad, but the concept is not.
Taking your example, and extending it you get:
enum
{
One = 1,
Two = 2,
Three = 3
}
If you insert a new value you give it a new number. So long as you make sure you have no duplicates then everything works out fine. Using this approach also forces the developer to think about what is going on - something that sadly doesn't seem to happen very often.
Also, I use enums frequently when using interop because Native API calls use a defined set of flags but it receives them as an int, although in C/C++ there would be lots of #defines making up the defined set of values. To pass these enums in to Native API interop calls you have to cast it to an int.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
I agree that putting values in enum is better, but if you work on a project with multiple people and have an enum without values, then next developer has no idea that you're using it as ints.
The solution I'm using now, is to store it as string and then use Enum.Parse to get the value back. I know it's quite a bit slower, but works better if enum is changing a lot.
|
|
|
|
|
Werdna wrote:
The solution I'm using now, is to store it as string and then use Enum.Parse to get the value back.
Eeuch! Sorry, but that is horrible.
Two things to mitigate this problem are:
1. Ensure the values are specified in advance. A good design should bing out most, if not all, the values you will need.
2. If it isn't known in advance [like the client changes their mind a lot, or you need to create space for future versions.] then space the numbers out - just like old fasioned programming languages where the line numbers would jump by 10 each time so you had space to add in additional code afterwards if needed.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
Yeah, I see what you mean. But I still can´t see the point of beeng able to declare an enum as:
enum ints :int {zero, one} if I can´t use it as constant int without convert. enum has always been an int in the background. If it is to be saved to file or something one should comment the code good enought so that the other people in the team knows not to change the order of the declarations. Or do them visible by:
enum ints { zero=0, one=1 } ; Then there should be no problem.
/ M
|
|
|
|
|
Mikke_x wrote:
Yeah, I see what you mean. But I still can´t see the point of beeng able to declare an enum as:
enum ints :int {zero, one} if I can´t use it as constant int without convert
The explicit cast is a safety mechanism - no matter how good your comments are you are not going to force someone to read them unless they have to. Most people muddle along all through their lives, programmers included. They only tend to look for something if they need to. The compiler forces them to need to.
The enum is there to say here is a type that can contain a set of possible values. If you want to assign it to an integer the compiler makes you explicity cast it to an integer (it probably does nothing when compiled - I've never checked the IL for that) because it is ensuring that you are fully aware that what you are doing is stripping off the protective layer that the enum is providing around the underlying int.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
Hi all,
I have 3 columns being read and displayed in a dataGrid. I want to trap the event when the 2nd column comes to focus.
How do I do this?
Thanks
|
|
|
|
|
I usually get chastised for missing an important detail or simpler method everytime I give advice, but I still like to try.
I would imagine your columns are just DataGridTextBoxColumns, since you didn't specify. Is there an event for when the grid gets focus, which you can simply see which cell has focus and determine if it's in the correct row? I'm too lazy to look myself.
If not, you could try making a new class which inherits the DataGridTextBoxColumn. In this class, you can have control of the textbox control which shows when a cell in the grid is activated. You can handle any events you want with the textbox. So, you can set the style of the grid so that the second column uses this new class, and the others just use the regular DataGridTextBoxColumn class.
Good luck, hope I helped.
|
|
|
|
|
Application Tools :Pocket PC 2003 , WINCE.NET , .NET CF , VC#
My startup form has 6 buttons ..each allowing user to jump to next screen.
Also every other screen returns to startup screen.
When I execute the application & navigate thru.
Every time i see a new instance of my startup form created at background.
i.e, when i leave my startup screen that particular instance doen't get closed/disposed.
My project requirements doesn't allow me to do FindWindow and DestroyWindow.
Could anyone suggest me why it is happenning and how to control it.
Thanks,
Ratna
|
|
|
|