C# syntax

  • Thread starter Thread starter msnews.microsoft.com
  • Start date Start date
M

msnews.microsoft.com

Hi,

C# is case sensitive

System.Drawing.Color localColor;

localColor = ((System.Drawing.Color)(ViewState["labelColor"]));

Lino
 
I am new to both C# and ASP.NET. I want to convert the VB.NET codes below to
C#:
Dim localColor As System.Drawing.Color
localColor = CType(ViewState("labelColor"), System.Drawing.Color)

I got an compilation error when I try the following code:
System.Drawing.Color localColor;
localColor = (System.Drawing.Color)(ViewState("labelColor");

Could someone tell me what is the equivalent codes in C#?
Also is there any site that shows all the C# syntaxes corresponding to those
of VB.NET?
 
you are missing a ) and to access the item from viewstate you need to use a
[] as it has an indexer.

but you dont need the (, so ...

System.Drawing.Color localColor;
localColor = (System.Drawing.Color)ViewState["labelColor"];

Will work.

ps

dident the compiler say you are missing )???
 
Thank both of you for your help. I missed one ) in my post but didn't miss
it in my original codes. I didn't understand the message that said that the
"Viewstate denotes a 'property' where a method was expected" until after
you pointed out the error with my using () instead of [].

Now my first question is solved but my second question still stands. Do you
know any site where I can look up C# syntaxes corresponding to those of
VB.NET?

Thank you.
 
System.Drawing.Color localColor =
(System.Drawing.Color)ViewState["labelColor"];

ViewState is an array, so use [], not () in C#. The cast was correctly done.
Why not do it all on one line, as above?

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
http://www.amazon.com/exec/obidos/t...f=sr_1_1/104-3375626-3360707?v=glance&s=books

Great book for understanding language differences. Will not teach you how to
code .NET, but will help you go back and forth from VB.NET to C# with ease.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
VC said:
Thank both of you for your help. I missed one ) in my post but didn't miss
it in my original codes. I didn't understand the message that said that the
"Viewstate denotes a 'property' where a method was expected" until after
you pointed out the error with my using () instead of [].

Now my first question is solved but my second question still stands. Do you
know any site where I can look up C# syntaxes corresponding to those of
VB.NET?

Thank you.

VC said:
I am new to both C# and ASP.NET. I want to convert the VB.NET codes
below
to
C#:
Dim localColor As System.Drawing.Color
localColor = CType(ViewState("labelColor"), System.Drawing.Color)

I got an compilation error when I try the following code:
System.Drawing.Color localColor;
localColor = (System.Drawing.Color)(ViewState("labelColor");

Could someone tell me what is the equivalent codes in C#?
Also is there any site that shows all the C# syntaxes corresponding to those
of VB.NET?
 
You should manage without a book, if you know vb.net you will manage with
c#, the first few bits of code will take awhile to get going but am sure you
will manage.

A quote from a well known Microsoft speaker at a conference (not word for
word :) ), 'when learning .NET, 10% of the effort goes into the language and
the other 90% the framework, chose the language your most familiar with then
move to different language' if you wish, this was amied at VBers getting
into C#.

Personally, I just jumped in with C# from VB6 background, but I have C++
under my belt so C# was quite easy.

Steve


VC said:
Thank both of you for your help. I missed one ) in my post but didn't miss
it in my original codes. I didn't understand the message that said that the
"Viewstate denotes a 'property' where a method was expected" until after
you pointed out the error with my using () instead of [].

Now my first question is solved but my second question still stands. Do you
know any site where I can look up C# syntaxes corresponding to those of
VB.NET?

Thank you.

VC said:
I am new to both C# and ASP.NET. I want to convert the VB.NET codes
below
to
C#:
Dim localColor As System.Drawing.Color
localColor = CType(ViewState("labelColor"), System.Drawing.Color)

I got an compilation error when I try the following code:
System.Drawing.Color localColor;
localColor = (System.Drawing.Color)(ViewState("labelColor");

Could someone tell me what is the equivalent codes in C#?
Also is there any site that shows all the C# syntaxes corresponding to those
of VB.NET?
 
Back
Top