473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Error Message : XXX is a 'type' but is used like a 'variable'

I may not be that good at C#, but I'm getting pretty good at asking questions :-D !!!

I need to "shuffle" an Array, I've found different ways of doing it but can't get any of them to work, this method seems straightforward enough, but I am getting the error "'KA_EMail_LeagueCup.Shuffle' is a 'type' but is used like a 'variable'".

I (think I) have created a Class called Shuffle.cs*, it has it's own tab and this is the code ...

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace KA_EMail_LeagueCup
  7. {
  8.     class Shuffle
  9.     {
  10.  
  11.     static Random _random = new Random();
  12.  
  13.     public static void Shuffle<T>(T[] array)
  14.     {
  15.     var random = _random;
  16.     for (int i = array.Length; i > 1; i--)
  17.     {
  18.         // Pick random element to swap.
  19.         int j = random.Next(i); // 0 <= j <= i-1
  20.         // Swap.
  21.         T tmp = array[j];
  22.         array[j] = array[i - 1];
  23.         array[i - 1] = tmp;
  24.     }
  25.     }
  26.     }
  27. }
... I then say this ...

Expand|Select|Wrap|Line Numbers
  1. Shuffle(KA_Team);
(where KA_Team is a filled string Array of 36 occurrences)

... and this is where I get the error. OK, I realise that I need to go back to my video course and learn a few more basics, but I was getting on so well with this earlier that I just ploughed ahead !!!
Sep 23 '11 #1
4 15068
GaryTexmo
1,501 Expert 1GB
You named your class Shuffle, and then you have a generic typed static method on that class that takes a parameter which is also called Shuffle. To call that method, you need to supply both the type, and the object the method will take. So for example, if you were using a list of integer objects, your code might look like this...

Expand|Select|Wrap|Line Numbers
  1. List<int> intList = new List<int>();
  2. intList.AddRange(new int[] { 1, 2, 3, 4, 5, 6 });
  3.  
  4. Shuffle.Shuffle<List<int>>(intList);
Do you see how you need to supply the type for the generically typed method as well as the object? Anyhoo, this is a bit confusing to read so you might want to consider renaming your class to something else. Perhaps something like Utils or ArrayUtils, or even going so far as to encapsulate your objects further by creating your own class to store values, then providing a method on it to shuffle. You have many options :)
Sep 23 '11 #2
Sorry, been away from this for a few days, just trying to figure out what you mean now !!!
Sep 27 '11 #3
Sorry GaryTexmo, I just don't understand :-(

I am going to go and watch a few more videos (learning ones, not leisure ones !!!), but in the meantime if it's possible for you to explain what you mean with an example or two I would appreciate it ...
Sep 27 '11 #4
Rabbit
12,516 Expert Mod 8TB
You have a class called shuffle. And you have a function called shuffle. It's assuming you're referring to the class.
Sep 27 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: James | last post by:
Hello Java NG, I not sure if this is the right NG for this type of question but if not please let me know which is, TIA Any way first off let me say I'm a student and this WAS last weeks lab,...
1
by: Michael Foitzik | last post by:
a.. Fehlertyp: Runtime error in Microsoft VBScript (0x800A01F4) Variable not defined: 'autoupdate_providerslots' /autoupdate/dictionaries/loadproviders.inc, line 16 a.. Browsertyp:...
7
by: Jack | last post by:
Hi, I have posted this problem before. Apprently, the suggestion took care of the problem. However, still I am getting the above error message. I am using a session variable to transfer a value...
1
by: JMCN | last post by:
hi, i have this form with the option filter. for some reason, whenever the user chooses OptCreateFilter = 3, they receive an error message "type mismatch 13." i looked at the data type of all...
1
by: iam247 | last post by:
Hi I am a relative beginner with SQL and ASP. With some help after previous posts I have a page which successfully requests querystrings from another page and deletes a record from an access...
4
by: octavio | last post by:
Hello members of the comp.lang.c newsgroup. Please I need you help on the following one. Compiling the simple code I'm getting this error message. Why ? Please what's the correct type of the fb...
3
by: dancer | last post by:
I am using Framework 1.1.4322. Who can tell me why I'm getting this error? My code follows Compilation Error Description: An error occurred during the compilation of a resource required to...
4
by: Jerry West | last post by:
I am new to VB .NET moving from VB6. I wrote the following code and as a result I received an error concerning it from the IDE. I don't understand why I get the message or why that what I am doing...
6
by: AAaron123 | last post by:
I'm using the CreateUserWizard Web Server Control The error message when the passwords do not match is colored red. Red does not show well against my background so I like to change that color. I...
4
by: Busbait | last post by:
Hi I am trying to declare a variable as a FileDialog object in VB for MS Access 2007 Dim fd As FileDialog But, I am receiving an error message “ Compiler error : User-Defined type not...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.