I can't stand this compiler.... I spent HOURS (!) trying to make

R

Radu

I am trying to write a webmethod which would look a bit like this:

-------------------------------------------------------------------------------------------------------
private string ConnectionString
{
get { return
ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString; }
}

public string[] GetCompletionList_LN(String prefixText)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlCommand command = new
SqlCommand("sp_DTDS_GetEmployeesByLastName", conn);
SqlParameter param1 = new SqlParameter("@Name", SqlDbType.VarChar);
param1.Value = prefixText;
command.Parameters.Add(param1);

SqlParameter param1 = new SqlParameter("@Counter",
SqlDbType.VarChar);
param2.Size = 3;
param2.Direction = ParameterDirection.Output;
command.Parameters.Add(param2);

conn.Open();

SqlDataReader dtr;
dtr = command.ExecuteReader();

List<String> items = new List<String>();
try
{
while (dtr.Read())
{
items.Add(dtr(0).ToString);
}
}
finally
{
conn.Close();
}

Return items.ToArray();
}
}

-------------------------------------------------------------------------------------------------------

I had
SqlParameter param1 = New SqlParameter("@Name",
SqlDbType.VarChar);
instead of
SqlParameter param1 = new SqlParameter("@Name",
SqlDbType.VarChar);
with "New" instead of "new"
so the compiler complained about
; expected
(?????)

What was the keyword "New" supposed to be, in the compiler's mind ? A
tulip ? Of course New is new !!! I have lost three hours hunting this
down ! This, or course, triggered other stupid error messages
downstream, like, for instance,

conn.Close();
was saying
Invalid token '(' in class, struct, or interface member
declaration
Huh ?


Anyhoo. I still have one problem - the line
Return items.ToArray();
says
; expected
and also typing "items" + dot does not trigger any type of
autocomplete.
Is there smething wrong with
List<String> items = new List<String>();
???

Please, what am I doing wrong here ? This makes me pull my hair out,
and I don't have much left.
I am a VBnet programmer, and this case-sensitivity in C# is the most
stupid thing I've met.

Thank you
Alex.
 
L

Lasse Vågsæther Karlsen

Radu wrote:
Anyhoo. I still have one problem - the line
Return items.ToArray();
says
; expected

Return is also written as a lower-case keyword, in fact, all the C#
keywords are lower-case (nagging feeling here that there is one that
isn't, but I can't come up with anything).
and also typing "items" + dot does not trigger any type of
autocomplete.

I assume this is in that line, in other words, you're writing:

Return items.

this will cause problems, because the compiler doesn't understand that
you're writing an expression where "items" is a valid word.
I am a VBnet programmer, and this case-sensitivity in C# is the most
stupid thing I've met.

Well, it is what it is, so you better get used to it, or continue using
VB.NET. I don't think there is much you can't do in VB that you can do
in C#, so I think you could easily switch back.
 
L

Lasse Vågsæther Karlsen

Tom said:
In C#: string = String
^ There's your one.
And about all the case insensitivity you are going to find.

No, that's not what I meant. string is the C# keyword for the BCL type
String and I know well the distinction. The nagging feeling is gone,
however, and could just be the effects of my lunch... who knows.
 
J

Jon Skeet [C# MVP]

Tom said:
In C#: string = String
^ There's your one.

No, only "string" is a keyword. String isn't.
And about all the case insensitivity you are going to find.

That's not case insensitivity. It's aliasing "string" for the type
"System.String".

In particular, it's very easy to come up with a program where using
"String" instead of "string" fails to compile:

class Test
{
static void Main(string[] args) {}
}

Just those four lines, on their own - they compile to a trivial
application. Change "string" to "String" and they won't, because
there's no "String" type and no using directives to guide the compiler
to System.String.

<snip>
 
J

Jon Skeet [C# MVP]

Lasse Vågsæther Karlsen said:
No, that's not what I meant. string is the C# keyword for the BCL type
String and I know well the distinction. The nagging feeling is gone,
however, and could just be the effects of my lunch... who knows.

The spec doesn't indicate any keywords beginning with a capital, as far
as I can see.

I don't suppose you're thinking of the preference for using "L" instead
of "l" as a suffix for longs, are you? (On the grounds that "l" can
look like "1", whereas "d", "m" and "f" don't have that issue.)

I reckon your lunch is the culprit here. What was it, anyway? :)
 
M

Michael A. Covington

Return is also written as a lower-case keyword, in fact, all the C#
In C#: string = String
^ There's your one.
And about all the case insensitivity you are going to find.

Technically, "string" is a C# keyword and "String" is a CLR type name; they
happen to denote the same thing, but this is not a matter of case
insensitivity, it's two synonymous words that happen to differ only in case.
 
L

Lasse Vågsæther Karlsen

Jon said:
The spec doesn't indicate any keywords beginning with a capital, as far
as I can see.

I don't suppose you're thinking of the preference for using "L" instead
of "l" as a suffix for longs, are you? (On the grounds that "l" can
look like "1", whereas "d", "m" and "f" don't have that issue.)

No, definitely not that.
I reckon your lunch is the culprit here. What was it, anyway? :)

Something with eggs... you know how that can go.
 
M

Martin Bonner

Technically, "string" is a C# keyword and "String" is a CLR type name; they
happen to denote the same thing, but this is not a matter of case
insensitivity, it's two synonymous words that happen to differ only in case.

Time to climb on my hobby horse here: Technically, String is /not/ a
CLR type name. However System.String is, and because most C# files
start with "using System;" you can refer to System.String as just
String.
 
B

Ben Voigt [C++ MVP]

RobinS said:
Don't feel too bad. When I first started C#, I spent 10 minutes one
day trying to figure out why this didn't work:

If (a == b)
{
}

(If should not be capitalized).


In other news, notepad is better at editing source code than Word.

RobinS.
------------------------
Radu said:
I am trying to write a webmethod which would look a bit like this:

-------------------------------------------------------------------------------------------------------
private string ConnectionString
{
get { return
ConfigurationManager.ConnectionStrings["DBConn"].ConnectionString; }
}

public string[] GetCompletionList_LN(String prefixText)
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlCommand command = new
SqlCommand("sp_DTDS_GetEmployeesByLastName", conn);
SqlParameter param1 = new SqlParameter("@Name", SqlDbType.VarChar);
param1.Value = prefixText;
command.Parameters.Add(param1);

SqlParameter param1 = new SqlParameter("@Counter",
SqlDbType.VarChar);
param2.Size = 3;
param2.Direction = ParameterDirection.Output;
command.Parameters.Add(param2);

conn.Open();

SqlDataReader dtr;
dtr = command.ExecuteReader();

List<String> items = new List<String>();
try
{
while (dtr.Read())
{
items.Add(dtr(0).ToString);
}
}
finally
{
conn.Close();
}

Return items.ToArray();
}
}

-------------------------------------------------------------------------------------------------------

I had
SqlParameter param1 = New SqlParameter("@Name",
SqlDbType.VarChar);
instead of
SqlParameter param1 = new SqlParameter("@Name",
SqlDbType.VarChar);
with "New" instead of "new"
so the compiler complained about
; expected
(?????)

What was the keyword "New" supposed to be, in the compiler's mind ? A
tulip ? Of course New is new !!! I have lost three hours hunting this
down ! This, or course, triggered other stupid error messages
downstream, like, for instance,

conn.Close();
was saying
Invalid token '(' in class, struct, or interface member
declaration
Huh ?


Anyhoo. I still have one problem - the line
Return items.ToArray();
says
; expected
and also typing "items" + dot does not trigger any type of
autocomplete.
Is there smething wrong with
List<String> items = new List<String>();
???

Please, what am I doing wrong here ? This makes me pull my hair out,
and I don't have much left.
I am a VBnet programmer, and this case-sensitivity in C# is the most
stupid thing I've met.

Thank you
Alex.
 
C

Chris Shepherd

Ben said:
In other news, notepad is better at editing source code than Word.

Yes, and NEVER let Outlook auto-capitalize for your if you're mailing code
samples. Best to use something akin to pastebin or send files in those
circumstances.

Chris.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top