I missed something important, interface members have to be public and therefore will be visible to the child classes. The answer will be that it will work up to the second generation, not beyond, if it's a requirement that classes have to inherit Class3 then it can't be done through design and needs some other solution. If the requirement is to only inherit from the second class, then all childer classes can be sealed to force to inherit from Class2 or Class1 but not from Class3 and beyond. Reflection would not be a solution because it would enforce it at runtime, not compile time, basically it would simply throw an error if the separate implementation is not there but it would compile fine. -- modified at 23:14 Saturday 1st April, 2006
ricardojb
Posts
-
Question about polymorphism.. -
Question about polymorphism..that wasn't the requirement, you can either declare the third class as sealed (then they can't inherit it) or otherwise continue hidding the methods from the child class by declaring them protected and not public, I haven't tested this though.
-
Question about polymorphism..No I didn't, try it. what he wants to do is having the compiler enforcing it and the code I posted will just do it. The interface will require the class to implement the method, normally that wouldn't be enough to enforce to rewrite it because it's already implemented by a parent class, but because it's protected and not public or internal, the child class won't see it and therefore the compiler requires the implementation of the interface. I didn't say it but it should be obvious that both methods (in the interface and the abstract class) need to have the exact same signature, that is, same name, same return type and same parameters.
-
Question about polymorphism..no, I didn't miss it, using the interface in this context has the sole purpose of enforcing it, that's the only reason to declare the same method in an abstract class and an interface, he is still inheritting from the class he wants to inherits but the compiler will force the developer to implement the method in the third class. And btw, I tested it, if you don't implement the method in the last class you get a compiler error, even though it inherits Class2 that already implemented the method.
-
ASP Code Migration to ASP.netI don't know if this might sound too simple, but a number of lines are commented out and therefore won't execute, I don't know if it's just the transcription you copied here or your code is like this. 'Response.BinaryWrite(lynxServer.responseBody) 'Response.Flush() 'Response.End() for example, I am more a C# programmer and not too familiar with VB.net but this lines of code would not be compiled in C#, they would simply be considered comments.
-
How to fire event in client side?you need to use client side scripts for that, such as javascript or vbscript (only in IE).
-
Help me! How to write a webcam aplication on ASP.NET????that sounds more like a socket application than an asp.net application. asp.net is to write web applications, meaning that they are processed on the server and send to the client in the form of html, xml, javascript and css. Unless you use an active X control (not an easy or good solution) you won't be able to get feed from the client, you cannot include a video stream in an http request which is all you will get from the client in a web application. You will need to install software on the client's machine, either a full windows application or at least an activex control or an IE add in (which is an activeX). Having said that, even in that case it's not going to be easy, because you have to directly interact with hardware, I am not too sure but I believe it's twain api is not even exposed as a win32 api but as a native api.
-
urgent !implementing excel function in asp.netdo you want to use Excel to do this or you want to write a method that does what Excel does? If you have Office 2003 you can install the primary interop assemblies that are basically .net wrapped classes of Office. then you can add references to these assemblies and use Excel or word classes in your application. You can always use com interop to interact with Excel, but the Excel object model is quite complex and poorly documented, so it might not be an easy solution.
-
C# Cannot find filewhat do you mean with the file has no permissions set, if it has no permissions set it won't be accessible to anybody.
-
problem with dropdownlistyou are doing that on Page_Load, that only runs when the page loads, that's why it updates when you refresh the page, if you want to force it to update you need to call DataBind again. I don't know how you are updating the database, You might need to set the autopostback of controls that update the database to true. In that case you won't need a separate call to the DataBind method because it's executed at the database level, however, it also depends on what you are doing the the dropdownlist, if you want to keep the selection the user makes you need to check the IsPostBack property and not bind the control every time the page loads,again, not knowing more is difficult to say how to do it.
-
Question about polymorphism..public abstract class Class1 { protected abstract void Method1(); } public interface IInterface1 { void Method1(); } public class Class2: Class1 { protected override void Method1() { //.... } public void HelperMethod() { this.Method1(); } } public class Class3 : Class2, IInterface1 { } this would do it, I don't really see why you would to through all this trouble but it will work. Class1 is abstract and declares a protected abstract method that Class2 must implement. Interface1 also requires the same method. Class3 inherits Class2 and the interface, but because the method is protected, it can't see it, so it needs to explicitly implement it because of the interface, additionally, the HelperMethod gives public access to Method1, this way the method is still public but the Method that follows the rules is not visible to the classes down the hierarchy.
-
Help me please..I don't know how you separate each number, but let's assume it's comma separated values, like 1,3,9,75. The first thing you have to do is separate this values, you can use the Split method of the string class. char[] separator = new char[1]; separator[0] = ','; string[] numbers = textbox1.Text.Split(separator); double[] coeficients = new double[numbers.Lenght]; for (int i = 0; i < numbers.Lenght; i++) { try { coeficients[i] = double.Parse(numbers[i]); } catch { } }
-
ToolStripTextBoxI don't think you can, you can always handle the keypress and keydown events to overwrite what the user types
-
C# ComboBox Questionsthe ComboBox has its own set of properties that can be assigned values just as any other control. If you select the control and have the properties windows open (if not go to view --> properties) you should see all the public properties of the control (usually the properties window displays on the bottom right side of the ide's window, unless you have configured visual studio to use floating and not docked windows).
-
multi-project solutionsthat depends on what you want to achieve. Usually, you will place more than one project in the same solution if they are related (not necessarily means they will run together), but many times, if you are developpig a multitier application, you will have for example your main project, which will generate an .exe (windows or console application) and some class libraries that will generate a .dll, you can run code from those class libraries by adding a reference to them to your main project (the .exe) and then, you can create instance of the classes, call methods, set properties. etc.
-
problem with dropdownlistif you dropdownlist is called for example dropDownList1. dropDownList1.DataBind();
-
how to verify is a website is up using javascriptWe have a web page with some javascript that displays information from an external site, occassionally, the external website is down and that slows down our site. We would like to either be able to test if the site is up before executing the javascript code, or implement some form of timeout mechanism (not what is defined as timeOut in javascript, which is really a sleep function), it would actually mean that if the website doesn't respond in a certain interval of time, we could either show a message or just bypass the execution all together. I haven't been able to find anything on this, any ideas?
-
IList vs array performance observation (.NET 2.0)Of course there will be a performance penalty for using a collection over an array. Even though with generics you can easily implement strongy typed collections (avoiding casting and boxing unboxing), the collections in fact use arrays. They provide you with more flexibility than an array (like you don't need to know the number of elements and they can grow as needed) but basically what it does is array operations. There are some ways you can improve performance, if you know the number of items you can setup the MaximumLenght property of your collection. Also, both with arrays and collections, whenever you try to access a member, the CLR will perform a bound check. but if you access it in a for loop, where you expressely use the .Count, or .Lenght property, the compiler is smart enough to detect that and won't do bound checks with a considerable performance gain (in long running loops). for example suppose you have an array a and you want to iteract. you can do it like this: int limit = a.Lenght; for (int i = 0; i < limit; i++) { } this will do a bound check for each iteraction. if you do for (int i=0; i < a.Lenght; i++) { } this boundcheck will not be performed.
-
Trigger CommandName=Edit/Select from DropDownList in GridViewAlright, this can get a little tricky. Option 1, use buttons or links. You just can add a Select column or just use the smart tag and check the Enable Selection checkbox and the IDE will add the column for you. Then, your detailsview will have to take the value of EmployeeId from the GridView, to do that you have to add EmployeeId to the DataKeyNames collection of the gridview (so the selected value will be the employeeid). Now, this IS tricky, because depending on the datasource your are using, the DetailsView will try to get the data, so you either will have to select one row in the GridView when you load the page or set the default value of the SelectParameter in the DetailsView's DataSource so it will return nothing if nothing is selected. (hope I've been clear) Then your details view could handle the other operations. If you must use a dropdown, then you will have to do everything in code, that is detect which selection was made and then get the data for the DetailsView and explicitly bind it. You will have to do two additionals things. First, you will have the AutoPostBack property of the dropdown to true. Second, if the user selects "Edit", you will have to add this code MyDetailsView.ChangeMode(DetailsViewMode.Edit); otherwise you will force the user to take another step to enter edit mode. hope it helps, it takes a little bit to get used to the new controls but once you do they are great.
-
.net 2.0Visual Studio 2003 cannot use .net 2.0. You will only be able to use the new classes from within VS 2005