|
fyi : < note code only tested in VS Studio beta 2 against FrameWork 4.0 >
If you are defining a generic class template that inherits from a generic List whose type is specifically defined as a "real" type at compile time like this :
public class anyDamnList3<T> : List<int>
{
public List<int> innerList
{
set
{
this.Clear();
this.AddRange(value);
}
}
}
the above will work. Of course you have to use its public property 'innerList to assign its "inner hidden list" value :
anyDamnList3<int> myList5 = new anyDamnList3<int> { 12, 21, 32 };
anyDamnList3<int> myList6 = new anyDamnList3<int> { 42, 53, 66 };
myList6.innerList = new List<int> { 33, 44, 55 };
So : no getting around having to define at least property in the class, and use Clear and AddRange !
The much more interesting case is this : where you are defining a generic strongly typed class which inherits from a List whose content type is generic <t> at compile time :
public class anyDamnList<T> : List<T>
{
public List<int> innerList
{
set
{
this.Clear();
this.AddRange(value as List<T>);
}
}
}
Yes, of course, you could define a method to set the "hidden inner list" rather than a property. Define to your own taste
You may note that in both cases above in actual use the "indexer" [] is exposed automatically. In essence you have every facility that comes with a List<t> type available to you except the ability to automatically assign to the "internal list it embodies." And, of course, just using the instance name returns the contents of what I am calling the "internal list" : in effect you have an automatic 'getter.
Thanks for the responses. I am going back to studying Skeet's magnificent book for a while !
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
Hello, everyone! I'm in need of assistance. I have to write a program calculating a user's input in a switch case.. I'm having problem.. Within my switch case, I reference a method to execute if the case statement is true.
A Little about my program:
The user will be given a menu. User will then select the option they desire and the amount they would like... User can keep entering the same option over and over(which I initialize the counter).
Here's a snippet of my code.
This is a Method of the Switch:
static void SwitchIntialize(ref int userResponse)
{
switch (userResponse)
{
case 1:
GetY(out yQ, out yTotal);
break;
case 2:
{
GetZ(out zQ, out zTotal);
}
break;
default:
{
Console.WriteLine("Sorry, You've entered an Invalid Number");
Console.WriteLine("Please try Again!!");
}
break;
}
}
Now, This is my Method
static void GetY(out double yQ, out double yTotal)
{
const double yPrice = 60.5;
Console.WriteLine("How many pounds would you like of Y? ");
yQ = Convert.ToDouble(Console.ReadLine());
yQ += yQ;
yTotal = yQ * yPrice;
}
static void GetZ(out double zQ, out double zTotal)
{
const double zPrice = 20.39;
Console.WriteLine("How many pounds would you like of Z? ");
zQ = Convert.ToDouble(Console.ReadLine());
zQ += zQ;
zTotal = zQ * zPrice;
}
For my final output, I will have to display how many lbs of X,Y, and Z the user purchase and the price of it..
I've also, declare it in my main as,
SwitchIntialize(ref int userChoice)
The Errors, that I've encountered are:
The Name yQ does not exist in the current context.
The name yTotal does not exist in the current context.
The best overloaded method match 'Program.GetY(out double, out double); has some invalid arguments
Argument '1': cannot convert from 'out yQ' to 'out double'
Argument '2': cannot convert from 'out yTotal' to 'out double'
The Name zQ does not exist in the current context.
The name zTotal does not exist in the current context.
The best overloaded method match 'Program.GetZ(out double, out double); has some invalid arguments
Argument '1': cannot convert from 'out zQ' to 'out double'
Argument '2': cannot convert from 'out zTotal' to 'out double'
|
|
|
|
|
DevonDaDude wrote: GetY(out yQ, out yTotal);
If you have you declared your variable types yQ and yTotal somewhere outside switchinitialize then declare them as static.
static double yQ;<br />
static double yTotal;
The same goes for all the other variables.
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
Why would he want to declare them as static? There would appear to be no need for a single copy of them regardless of the number of instances.
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Simple.
I did not see any variables in his method. So he's missed them. And if he wants to declare them in the class (as class variables) he would have to declare them as static (otherwise the project would not even build). Its entirely up to him.
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
Abhinav S wrote: And if he wants to declare them in the class (as class variables) he would have to declare them as static (otherwise the project would not even build)
Not true. You can declare as class variable without static method.
example:
public class myClass
{
public myClass()
{
str = "This has a string";
}
public void WhatIsInString()
{
MessageBox.Show(str);
}
public String str;
}
static is useful when you want variable to be accessible anywhere within project
|
|
|
|
|
Saksida Bojan wrote: public String str;
That's not a class variable, it's an instance variable. Class variables are static , i.e. there is only one copy regardless of how many instances of the class exist. This is different from a static variable defined at the module level which does not belong to a class.
|
|
|
|
|
Thanks, everyone.. Abhinav, thank you as well, I use private static double yQ; and I got it working. Thanks
|
|
|
|
|
From the error messages, I think you need at add a few statements to your method, just amove the switch:
double yQ;
double yTotal;
double zQ;
double zTotal;
This will declare the missing variables, and should get rid of the error messages.
From a stylistic point of view, have you noticed how similar your two routines getY and getZ are? Perhaps you could combine them into one, so it would be easier to maintain?
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
0) You probably want to use ref rather than out unless you're somehow calculating the total after the switch.
1) There's no need to assign yQ/zQ twice.
zQ += Convert.ToDouble(Console.ReadLine());
And why not use double.TryParse ? And handle bad input?
2) Pay better attention to the teacher and your textbook.
|
|
|
|
|
Thanks everyone, for your input..I do appreciate it.. I'll try all of the above..
Someone said, I should
* Declare all the variables use - I did declare it, I just gave small snippet of the code.
* No Need to assign yQ/zQ - I'm applying what i've learned, I was unaware I could do something like that.
* Double.TryParse - I'm unfamiliar with that, I only know what my book and teacher, taught us.
* I do pay attention to the teacher and my textbook.
* I cannot change it to a if..else statement.. The requirements for this program is to use switch case.
Again, I do appreciate all of your inputs. Thank You, Very Much!
|
|
|
|
|
Dear friends,
Can someone please Explain me about << and >> operator
and diffrence between | and || operator
and where it can be Used. and some example please
by
joe
modified on Saturday, December 12, 2009 1:35 AM
|
|
|
|
|
Try here [^].
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
<< and >> do a bitwise shift in the indicated direction the specified number of places. Think of them like n x 10 and n / 10 in decimal (base 10), but in binary (base 2) so they are effectively n * 2 and n / 2 if shifting by one.
| does a bitwise OR where each binary digit is ORed with it's counterpart. This is the OR truth table for each bit in two values being ORed, the first column is the first value, the second column is the second value and the final column is the result:
--------
|0|0||0|
|0|1||1|
|1|0||1|
|1|1||1|
-------- A logical OR || is the same except it can only operate on a boolean value and returns a boolean, so replace the 0s in the table with false and the 1s with true.
Unless you're doing binary operations then you won't use them every day. One place I had to use them recently is in getting/creating the constituent bytes of a MIDI packet. All 'short' MIDI messages are between 1 and 3 bytes long. An Int32 is 4 bytes so Microsoft chose to place all packets in one Int32. If I use a NoteOn as an example:
1001cccc : byte0 = status (c = channel)
0nnnnnnn : byte1 = note number
0vvvvvvv : byte2 = velocity
As an Int32: xxxxxxxx0vvvvvvv0nnnnnnn1001cccc
So to build this Int32 from 3 bytes status, note, velocity) I need to start with status, then left shift note by 8 bits and velcity by 16 bits then OR them all.
Int32 intStatus = status;
Int32 intNote = (note << 8);
Int32 intVelocity = (velocity << 16);
Int32 packet = intStatus | intNote | intVelocity;
To get the bytes out, a 'mask' is needed and a logical AND combined with a right shift
Int32 statusMask = 0x000000FF;
Int32 noteMask = 0x00007F00;
Int32 velocityMask = 0x007F0000;
byte status = (byte)(packet & statusMask);
byte note = (byte)((packet & noteMask) >> 8);
byte velocity = (byte)((packet & velocityMask) >> 16;
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
modified on Saturday, December 12, 2009 1:38 PM
|
|
|
|
|
Thank you friend...thanks for your replay.
i could not understan your code fully but i got somthing about the operator
thank U
|
|
|
|
|
You're welcome
In case you want to improve your English, it's 'reply' not 'replay' - a common mistake
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thank You...
|
|
|
|
|
|
Hello Friends,
i am working in a desktop application in VS 2008 using C#. And i am creating some crystal reports against search records. Say i have generate my reports against a Selected Client. Generate crystal report against single client is simple and straight forward.
Now i want to select multiple clients and generate there reports and want to display all of them in single viewer. so i can achieve this?
Second reports will show after the end of first report and will be on next page but in same viewer.
Please help me to achieve this functionality. If possible let me know some sample code for this.
Thanks
Sher Azam
modified on Saturday, December 12, 2009 1:31 AM
|
|
|
|
|
Could you design all of your reports as sub reports?
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
actually the number of sub reports can be any that's why i am not preferring it. is there any other solution that i can add multiple reports of same type in single viewer.
|
|
|
|
|
Hi:
As everyone might be aware of Microsoft Multipoint SDK, I have been trying to do a project based on this SDK.
This SDK provides us the capability to use several mice on a single computer(obviously several cursors). Everything is fine, but it has only two controls, namely; Multipoint Button and Multipoint TextBox. Now, what if I need to have my own user control?? Please help me out. I am jus stuck.
Thanks.
|
|
|
|
|
HI,
I have createad a custom control for MultipointSDK for making my game with it
You could visit the post on this link
social.msdn.microsoft.com/Forums/en/mptgen/thread/470ba298-0617-4da4-9ba3-bfa0e359e994
Ok you would get the idea
Good bye
|
|
|
|
|
Hi,
I got this chart object on my UI thread called 'm_ChartControl'
I got a method called AddAnnotations that will be run on a new thread in my Form_Load method.
Inside my AddAnnotation method there is a line of code that do this.
Annotation a = m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();
But m_ChartControl.Charts[0].AnnotationList.CreateAnnotation(); is in the UI thread.
How do i create a delegate to put it here?
I have tried this.
private delegate Annotation AddAnnotation();
AddAnnotation addNewAnnotation;
private Annotation CreateAnnotation()
{
return m_ChartControl.Charts[0].AnnotationList.CreateAnnotation();
}
void cAnnotation()
{
this.Invoke(addNewAnnotation);
}
I changed this to
Annotation a = cAnnotation();
and i get this error
Error 18 Cannot implicitly convert type 'void' to 'Manco.Chart.CF.Layout.Annotation'
|
|
|
|
|
Threading in .NET and WinForms[^]
void cAnnotation()
{
AddAnnotation del = new AddAnnotation();
this.Invoke(del);
}
public Annotation()
{
//This function will be referenced and executed on destination form/control
}
|
|
|
|