|
Since Processors is a collection contained in the Team class you can access it as
Team.Processors.Alphas
you need an indexer
Team.Processors[x].Alphas
only two letters away from being an asset
|
|
|
|
|
Here is example code I made for this question:
using System;
namespace TestingAs
{
class baseClass
{
public string foo
{
get;
set;
}
}
class derivedClass : baseClass
{
public string bar
{
get;
set;
}
}
class Program
{
static void Main(string[] args)
{
derivedClass derived = new derivedClass();
baseClass b = derived as baseClass;
Console.WriteLine("type is {0}", b.GetType());
Console.ReadLine();
}
}
}
I also tried just casting baseclass b = (baseClass)derived; which gives the same result:
type is TestingAs.derivedClass
Why b is not type of baseClass ? How would I "convert" my derived class into base class type?
Thank you in advance!
|
|
|
|
|
This is the same concept of Reference Copying.
In runtime the pointer of the object is set to derived class object. Thus it will always hold the derivedclassobject even if you cast it to base class object.
|
|
|
|
|
Convert.ChangeType ?
Why would you want to?
|
|
|
|
|
Does it matter why I want to?
My app is using .dll's which are returning class arrays.
My previous problem was that the application was completed and working well when it was required to use custom data in a way I found "good" solution to change my application to use derived class from the class type returned from the .dll layer, it just worked as long as I did not need to use same class array objects as parameters in .dll layer method calls.
|
|
|
|
|
I didn't quite follow all that, but I still see no reason to downgrade the instances.
|
|
|
|
|
Think about it. When you derive a class from baseClass, you are adding information to baseClass. When you try to convert your derived class to a baseClass, you would have to throw information away. You could not recover the information by re-casting your item to a derivedClass, because otherwise your program would have to behave very differently with the following :
derivedClass d = new derivedClass();
baseClass b = d as baseClass;
derivedClass d2 = (derivedClass) b; and
baseClass b = new baseClass();
derivedClass d2 = (derivedClass) b;
If the definitions were in (say) different methods to the casts, it could get very difficult to work out what is going on.
Since wherever you can use a baseClass, you can use any derived class, C# is not keen on throwing away information, which could not be recovered by a re-cast back to the derived class.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
|
Im trying to track how long between certain things happening in my app. When the first event happens im adding the time to an array like this: myArrList.Add(DateTime.Now);
Then when the next event happens im retreiving it from the array and doing this:
TimeSpan diff = DateTime.Now - (DateTime)myArrList[x];
But for some reason it always gets like 0.02 seconds. Which makes me think that its doing the current time minus the current time(and the 0.02 is the time it takes between finding the first time and the second).
So how do i do this properly?
Am I adding a reference to DateTime.Now into the array instead of just the value?
Thanks
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
No, when you get DateTime.Now you get just that - the time now, which will not change thereafter. So if you write
DateTime dt = DateTime.Now;
at noon, dt will still say noon at 13:00.
How long is the actual interval between the two events? Are we talking microseconds? Seconds? Minutes? How frequently is your event happening? Once? Or every (say) 20ms?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Well it is usually around a second or less
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
You might want to take a look at the Stopwatch[^] class
only two letters away from being an asset
|
|
|
|
|
Looks good! TY
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
roguemat wrote: Am I adding a reference to DateTime.Now
No. DateTime is a value time (a struct), no references involved.
roguemat wrote: it always gets like 0.02 seconds
DateTime.Now as well as the system clock get updated only a few times a second (typ. 60 Hz); see my timers article. If you need better accuracy, use a Stopwatch.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Will check it out thanks!
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
Hi , I am developing software to read the tiff images. i need to read the text written in tiff images programmatically in c#. I have lakhs of tiff image to process it for cleaning and reading. also i want to develop thumbnails programmatically of those tiff scanned images.
Regards,
Lalit Singh
Programmer Analyst
Hitech Outsourcing Services
|
|
|
|
|
How about searching it in codeproject, search for "OCR". You find lots of article of it.
|
|
|
|
|
Salut,
Lorsque je click sur le multicolumncombo, je veux avoir une table de 2 colonnes qui ont pour noms codeArticle et
description et cette table est remplie à partir de la base de données.En selectionnant une ligne,la description
sera affichée.Est-ce qu'il y a quelqu'un qui peut m'aider à faire ceci?
|
|
|
|
|
Vous obtiendrez une réponse plus rapide si vous utilisez l'anglais.
Thank heavens for google translate.
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|
Here's a 5 just for making the effort to translate it.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Vous pourriez avoir plus de chance demandant aux auteurs de ces contrôles dans leur forum de support comme la plupart des gens ici n'ont pas travaillé avec ces contrôles.
|
|
|
|
|
Parlez-vous de contrôle d'élaborer sur mesure?
Il n'ya rien comme combo multi-colonnes en. NET.
|
|
|
|
|
MultiColumnCombo est un contrôle de la bibliothèque janus.
|
|
|
|
|
Hi, I'm currently working on a cyber cafe program and I need to use 2 timers for each table's calculations and there are 25 tables(pc's).The question is, does using many timers(with 100ms intervals) have any impact on the performance?
And referring to 2 timers, there are two different calculations(time and price)which occur at different intervals.Is it possible to handle them in one timer?
last question(sorry ) Is it good to make all controls and variables public to access from other forms?
Your help would be appreciated,thanks
|
|
|
|
|
I can answer the last, and probably the second of those.
teknolog123 wrote: two different calculations(time and price)which occur at different intervals.Is it possible to handle them in one timer?
Only if the two intervals happen at multiples of each other. If one is due at 100ms and the other at 123ms intervals, then you cannot handle them both easily from the same timer. If one is due ate 100ms and the other at 500ms intervals, then yes, just count 5 instances of the timer event.
teknolog123 wrote: Is it good to make all controls and variables public to access from other forms?
No. This is very bad practice as it locks the design of your form, and you cannot change it without making changes in an unknown number of other forms. Use public properties instead, as the underlying form elements are hidden and can be changed without affecting external code.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|