A simple code example is easier than trying to describe the issue. I
have:
public class myClassA
{ 11 4985 pa*********@abbott.com wrote:
A simple code example is easier than trying to describe the issue. I
have:
public class myClassA
{
.
.
.
}
public class myClassB {
.
.
public List<myClassAclassBfunc()
{
.
.
.
}
.
.
}
When I attempt to compile, I get the error "} expected" on the line
containing the opening curly brace of classBfunc(). What am I doing
wrong? Is what I'm trying possible?
I get a different error: "Invalid token '.' in class, struct, or interface
member declaration".
Please post complete examples if you want compile errors diagnosed,
otherwise it's impossible for us to tell where the actual error might be.
What you want to do is possible and you're using the correct syntax, so it's
anyone's guess.
--
J.
public List<myClassAclassBfunc<myClassA>()
{}
The generic parameter needs to be passed to the function
<pa*********@abbott.comwrote in message
news:2d**********************************@c65g2000 hsa.googlegroups.com...
>A simple code example is easier than trying to describe the issue. I
have:
public class myClassA
{
.
.
.
}
public class myClassB {
.
.
public List<myClassAclassBfunc()
{
.
.
.
}
.
.
}
When I attempt to compile, I get the error "} expected" on the line
containing the opening curly brace of classBfunc(). What am I doing
wrong? Is what I'm trying possible?
TIA
Bill McCarthy wrote:
public List<myClassAclassBfunc<myClassA>()
{}
The generic parameter needs to be passed to the function
Good catch! This is the difference between
public List<myClassAclassBfunc()
with
public List<myClassAclassBfunc<myClassA>()
The former is a non-generic method that returns a particular instantiation
of List with the type "myClassA". The latter is a generic method that
returns an instantiation of List using the type parameter "myClassA".
If "myClassA" is not defined, the first one is an error. So if "myClassA" is
a concrete type, the OP's probably missing an assembly reference.
--
J.
"Jeroen Mostert" <jm******@xs4all.nlwrote in message
news:48*********************@news.xs4all.nl...
Bill McCarthy wrote:
> public List<myClassAclassBfunc<myClassA>() {}
The generic parameter needs to be passed to the function
Good catch! This is the difference between
public List<myClassAclassBfunc()
with
public List<myClassAclassBfunc<myClassA>()
The former is a non-generic method that returns a particular instantiation
of List with the type "myClassA". The latter is a generic method that
returns an instantiation of List using the type parameter "myClassA".
If "myClassA" is not defined, the first one is an error. So if "myClassA"
is a concrete type, the OP's probably missing an assembly reference.
Just looked at the original code again and he did define myCLassA, so the
intent is probably a concrete List, but in which case I can't see where the
error could be . The thread title threw me off ;)
Bill McCarthy <Bi**@localhost.comwrote:
public List<myClassAclassBfunc<myClassA>()
{}
The generic parameter needs to be passed to the function
Only when it's meant to be a generic method. There's nothing to
indicate that here. Put it this way - would you have seen anything
wrong if the OP hadn't posted myClassA at all, but had posted:
public class myClassB
{
public List<stringclassBFunc()
{
...
}
}
?
--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Bill McCarthy wrote:
>
"Jeroen Mostert" <jm******@xs4all.nlwrote in message
news:48*********************@news.xs4all.nl...
>Bill McCarthy wrote:
>> public List<myClassAclassBfunc<myClassA>() {}
The generic parameter needs to be passed to the function
Good catch! This is the difference between
public List<myClassAclassBfunc()
with
public List<myClassAclassBfunc<myClassA>()
The former is a non-generic method that returns a particular instantiation of List with the type "myClassA". The latter is a generic method that returns an instantiation of List using the type parameter "myClassA".
If "myClassA" is not defined, the first one is an error. So if "myClassA" is a concrete type, the OP's probably missing an assembly reference.
Just looked at the original code again and he did define myCLassA, so
the intent is probably a concrete List, but in which case I can't see
where the error could be .
The error is that the compiler can't find myClassA -- it gives exactly the
message reported by the OP in this case. His code isn't representative of
what he posted; most likely myClassA isn't in the same namespace as myClassB
and he forgot to add a reference.
Again, it all just goes to show you that minimal complete examples are not
optional in these cases...
--
J.
"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
Bill McCarthy <Bi**@localhost.comwrote:
> public List<myClassAclassBfunc<myClassA>() {}
The generic parameter needs to be passed to the function
Only when it's meant to be a generic method. There's nothing to
indicate that here. Put it this way - would you have seen anything
wrong if the OP hadn't posted myClassA at all, but had posted:
public class myClassB
{
public List<stringclassBFunc()
{
...
}
}
?
Yep the ... and ? <g Actually I think the problem with his code is
probably a namespace before the classes and not the closing } on the
namespace. The title of the thread and the function code/return type
probably aren't the issue at all ;)
Jeroen Mostert wrote:
Bill McCarthy wrote:
>> "Jeroen Mostert" <jm******@xs4all.nlwrote in message news:48*********************@news.xs4all.nl...
>>Bill McCarthy wrote: public List<myClassAclassBfunc<myClassA>() {}
The generic parameter needs to be passed to the function
Good catch! This is the difference between
public List<myClassAclassBfunc()
with
public List<myClassAclassBfunc<myClassA>()
The former is a non-generic method that returns a particular instantiation of List with the type "myClassA". The latter is a generic method that returns an instantiation of List using the type parameter "myClassA".
If "myClassA" is not defined, the first one is an error. So if "myClassA" is a concrete type, the OP's probably missing an assembly reference.
Just looked at the original code again and he did define myCLassA, so the intent is probably a concrete List, but in which case I can't see where the error could be .
The error is that the compiler can't find myClassA -- it gives exactly
the message reported by the OP in this case. His code isn't
representative of what he posted; most likely myClassA isn't in the same
namespace as myClassB and he forgot to add a reference.
Again, it all just goes to show you that minimal complete examples are
not optional in these cases...
Hmm - the OP never did come back with a complete example, so it seems like you
may have shown the reverse, actually . . .
-rick-
Rick Lones wrote:
Jeroen Mostert wrote:
<snip>
>Again, it all just goes to show you that minimal complete examples are not optional in these cases...
Hmm - the OP never did come back with a complete example, so it seems
like you may have shown the reverse, actually . . .
If all you care about is the solution, yes. A *speedy* solution, on the
other hand... In this case we just got lucky that the problem was simple
enough to diagnose by exhaustion. Generally, trying to guess what someone's
code might be doing wrong if they don't show it is nigh impossible.
--
J. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: matty.hall |
last post by:
I have two classes: a base class (BaseClass) and a class deriving from
it (DerivedClass). I have a List<DerivedClass> that for various
reasons needs to be of that type, and not a List<BaseClass>....
|
by: PJ |
last post by:
I have a class definition :
public class PagingList<T> : List<T>
{
private int pageSize, pageNumber;
public PagingList()
{
pageSize = (this.Count == 0) ? 1 : this.Count;...
|
by: Jeff.Boeker |
last post by:
I'm learning a lesson in how I need to be more specific :)
In C++ I can resize a vector and it will allocate memory and it will
call the default constructor if necessary (or I can supply an...
|
by: Iron Moped |
last post by:
I'm airing frustration here, but why does LinkedList<not support the
same sort and search methods as List<>? I want a container that does not
support random access, allows forward and reverse...
|
by: Andrew Robinson |
last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v>
depending on input parameters and options to the method.
1. Is there any way to convert from a dictionary to a list...
|
by: Zytan |
last post by:
The docs for List say "The List class is the generic equivalent of the
ArrayList class." Since List<is strongly typed, and ArrayList has
no type (is that called weakly typed?), I would assume...
|
by: Zytan |
last post by:
This returns the following error:
"Cannot modify the return value of
'System.Collections.Generic.List<MyStruct>.this' because it is
not a variable"
and I have no idea why! Do lists return copies...
|
by: Fred Mellender |
last post by:
I am trying to use reflection to output the fields (names and values) of an
arbitrary object -- an object dump to a TreeView.
It works pretty well, but I am having trouble with generic lists,...
|
by: Peter |
last post by:
I have a WebService which returns a List of RunningReport class
How do I read this XML data on the client side. How do I convert
List<RunningReportfrom the WebService side to List<RunningReporton...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |