PC Review


Reply
Thread Tools Rate Thread

Anyone knows the C# Equivalent

 
 
alee via DotNetMonster.com
Guest
Posts: n/a
 
      17th Feb 2007
Hello,

I am trying to convert a program from Microsoft VB.NET team:

http://blogs.msdn.com/vbteam/archive...ndObjects.aspx

I am having a hard time converting the following two sections. Anyone knows
the C# equivalent?


- oringial VB.NET code from VB Team:
Public Sub AcceptChanges()

For Each item As T In Me.Items

item.ObjectState = ObjectState.Unchanged

Next

DeletedRows.Clear()

End Sub

- my approach:
public void AcceptChanges()
{
foreach (T item in this.Items)
{
item.ObjectState = ObjectState.Unchanged;
}
DeletedRows.Clear();
}
- Visusal Studio error: 'T' does not contain a definition for 'ObjectState'

2. Original code from VB team:

Dim txScope As New System.Transactions.TransactionScope

Using txScope
...
end using

- my approach:

using txScope
{
...
}
- Visual Studio:

Syntax error, '(' expected

Best regards,

Alan L.

--
Message posted via http://www.dotnetmonster.com

 
Reply With Quote
 
 
 
 
sturnfie@gmail.com
Guest
Posts: n/a
 
      17th Feb 2007
On Feb 17, 10:52 am, "alee via DotNetMonster.com" <u31808@uwe> wrote:
> - my approach:
> public void AcceptChanges()
> {
> foreach (T item in this.Items)
> {
> item.ObjectState = ObjectState.Unchanged;
> }
> DeletedRows.Clear();
> }
> - Visusal Studio error: 'T' does not contain a definition for 'ObjectState'


What is your definition for "T"? I am assuming this article is using
it as a generic object, meaning you need to create it and what it is
supposed to be; in this case, give it a property of "ObjectState".
Read the article to figure out what the expectations of the object are
(namely, what it is supposed to be based on).


> - my approach:
>
> using txScope
> {
> ...
> }
> - Visual Studio:
>
> Syntax error, '(' expected
>


This is an issue of scope. The proper syntax is:

using (txScope)
{
....
}


--
lucas

 
Reply With Quote
 
=?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
Guest
Posts: n/a
 
      17th Feb 2007
alee via DotNetMonster.com wrote:
> - Visusal Studio error: 'T' does not contain a definition for 'ObjectState'


C# is case sensetive while VB is not. Have you checked the exact name,
so it isn't for example "objectState"?

> - my approach:
>
> using txScope
> {
> ...
> }
> - Visual Studio:
>
> Syntax error, '(' expected


using (txScope) {
...
}

--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
alee via DotNetMonster.com
Guest
Posts: n/a
 
      18th Feb 2007
Lucas,

Thanks for your suggestions. The using syntax works fine now.

However, I have tried several method to define the following VB.NET
equivalence without any luck.

VB.NET

Public MustInherit Class BaseList(Of T As BaseObject) Inherits BindingList(Of
T)

C# - tried

public abstract class BaseList<T as BaseObject> : BindingList<T>
public abstract class BaseList<T:BaseObject> : BindingList<T>

I just want to the generic T to inherit properties defined in BaseObject.

Cheers,

Alan L.




(E-Mail Removed) wrote:
>> - my approach:
>> public void AcceptChanges()

>[quoted text clipped - 6 lines]
>> }
>> - Visusal Studio error: 'T' does not contain a definition for 'ObjectState'

>
>What is your definition for "T"? I am assuming this article is using
>it as a generic object, meaning you need to create it and what it is
>supposed to be; in this case, give it a property of "ObjectState".
>Read the article to figure out what the expectations of the object are
>(namely, what it is supposed to be based on).
>
>> - my approach:
>>

>[quoted text clipped - 5 lines]
>>
>> Syntax error, '(' expected

>
>This is an issue of scope. The proper syntax is:
>
>using (txScope)
>{
> ....
>}
>
>--
>lucas


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...users/200702/1

 
Reply With Quote
 
alee via DotNetMonster.com
Guest
Posts: n/a
 
      18th Feb 2007
Hi Goran,

Thanks. The using syntax works, but I still have problem converting the
definition
for the generic T. I

public abstract class BaseList<T of BaseObject> : BindingList<T>

- I want the generic key argument inherits properties defined in BaseObject.

Originaal VB.NET syntax is:

Public MustInherit Class BaseList(Of T As BaseObject) Inherits BindingList(Of
T)

Cheers,

Alan L.


Göran Andersson wrote:
>> - Visusal Studio error: 'T' does not contain a definition for 'ObjectState'

>
>C# is case sensetive while VB is not. Have you checked the exact name,
>so it isn't for example "objectState"?
>
>> - my approach:
>>

>[quoted text clipped - 5 lines]
>>
>> Syntax error, '(' expected

>
>using (txScope) {
> ...
>}
>


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...users/200702/1

 
Reply With Quote
 
mehdi
Guest
Posts: n/a
 
      18th Feb 2007
On Feb 17, 7:52 pm, "alee via DotNetMonster.com" <u31808@uwe> wrote:
> Hello,
>
> I am trying to convert a program from Microsoft VB.NET team:
>
> http://blogs.msdn.com/vbteam/archive...aptersAndObjec...
>
> I am having a hard time converting the following two sections. Anyone knows
> the C# equivalent?
>
> - oringial VB.NET code from VB Team:
> Public Sub AcceptChanges()
>
> For Each item As T In Me.Items
>
> item.ObjectState = ObjectState.Unchanged
>
> Next
>
> DeletedRows.Clear()
>
> End Sub
>
> - my approach:
> public void AcceptChanges()
> {
> foreach (T item in this.Items)
> {
> item.ObjectState = ObjectState.Unchanged;
> }
> DeletedRows.Clear();
> }
> - Visusal Studio error: 'T' does not contain a definition for 'ObjectState'
>
> 2. Original code from VB team:
>
> Dim txScope As New System.Transactions.TransactionScope
>
> Using txScope
> ...
> end using
>
> - my approach:
>
> using txScope
> {
> ...
> }
> - Visual Studio:
>
> Syntax error, '(' expected
>
> Best regards,
>
> Alan L.
>
> --
> Message posted viahttp://www.dotnetmonster.com


Hi,

The first equivalent:
Well, you are trying to use a class (T) that is supposed to have an
ObjectState property. However, this should be explicitly declared
using the "where" keyword in C#. You need to change the class
definition to something as follows:

public class MyClass<T> where T: BizObjBase

this tells the compiler that T is of type BizObjBase...

The second equivalent:
using (TransactionScope txScope = new TransactionScope())
{
//do whatever you need with txScope
}

HTH,
Mehdi

 
Reply With Quote
 
=?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
Guest
Posts: n/a
 
      18th Feb 2007
If you have a base class for all objects that the class handles, then
you don't need to use generics at all in your class. Just use the base
class when you inherit the BindingList.

public abstract class BaseList : BindingList<BaseObject>

Now your BaseList is a BindingList that handles any object that inherits
from BaseObject.

In your method that loops the items, just reference them as BaseObject:

public void AcceptChanges() {
foreach (BaseObject item in this.Items) {
item.ObjectState = ObjectState.Unchanged;
}
DeletedRows.Clear();
}

alee via DotNetMonster.com wrote:
> Hi Goran,
>
> Thanks. The using syntax works, but I still have problem converting the
> definition
> for the generic T. I
>
> public abstract class BaseList<T of BaseObject> : BindingList<T>
>
> - I want the generic key argument inherits properties defined in BaseObject.
>
> Originaal VB.NET syntax is:
>
> Public MustInherit Class BaseList(Of T As BaseObject) Inherits BindingList(Of
> T)
>
> Cheers,
>
> Alan L.
>
>
> Göran Andersson wrote:
>>> - Visusal Studio error: 'T' does not contain a definition for 'ObjectState'

>> C# is case sensetive while VB is not. Have you checked the exact name,
>> so it isn't for example "objectState"?
>>
>>> - my approach:
>>>

>> [quoted text clipped - 5 lines]
>>> Syntax error, '(' expected

>> using (txScope) {
>> ...
>> }
>>

>



--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
Alvin Bruney [MVP]
Guest
Posts: n/a
 
      19th Feb 2007
Google instant C#, this application will translate your VB code into C#. It
is very good.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


"alee via DotNetMonster.com" <u31808@uwe> wrote in message
news:6df2e29b449bc@uwe...
> Hello,
>
> I am trying to convert a program from Microsoft VB.NET team:
>
> http://blogs.msdn.com/vbteam/archive...ndObjects.aspx
>
> I am having a hard time converting the following two sections. Anyone
> knows
> the C# equivalent?
>
>
> - oringial VB.NET code from VB Team:
> Public Sub AcceptChanges()
>
> For Each item As T In Me.Items
>
> item.ObjectState = ObjectState.Unchanged
>
> Next
>
> DeletedRows.Clear()
>
> End Sub
>
> - my approach:
> public void AcceptChanges()
> {
> foreach (T item in this.Items)
> {
> item.ObjectState = ObjectState.Unchanged;
> }
> DeletedRows.Clear();
> }
> - Visusal Studio error: 'T' does not contain a definition for
> 'ObjectState'
>
> 2. Original code from VB team:
>
> Dim txScope As New System.Transactions.TransactionScope
>
> Using txScope
> ...
> end using
>
> - my approach:
>
> using txScope
> {
> ...
> }
> - Visual Studio:
>
> Syntax error, '(' expected
>
> Best regards,
>
> Alan L.
>
> --
> Message posted via http://www.dotnetmonster.com
>



 
Reply With Quote
 
Barry Kelly
Guest
Posts: n/a
 
      19th Feb 2007
alee via DotNetMonster.com wrote:

> Public MustInherit Class BaseList(Of T As BaseObject) Inherits BindingList(Of
> T)


public abstract class BaseList<T> : BindingList<T>
where T : BaseObject


-- Barry

--
http://barrkel.blogspot.com/
 
Reply With Quote
 
alee via DotNetMonster.com
Guest
Posts: n/a
 
      19th Feb 2007
Hello Mehdi,

Thanks for your suggestions, and they work well.

Regards,

Alan L.

mehdi wrote:
>> Hello,
>>

>[quoted text clipped - 53 lines]
>> --
>> Message posted viahttp://www.dotnetmonster.com

>
>Hi,
>
>The first equivalent:
>Well, you are trying to use a class (T) that is supposed to have an
>ObjectState property. However, this should be explicitly declared
>using the "where" keyword in C#. You need to change the class
>definition to something as follows:
>
>public class MyClass<T> where T: BizObjBase
>
>this tells the compiler that T is of type BizObjBase...
>
>The second equivalent:
>using (TransactionScope txScope = new TransactionScope())
>{
> //do whatever you need with txScope
>}
>
>HTH,
>Mehdi


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...users/200702/1

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Equivalent for VB6 Mazant, K. Microsoft Dot NET 2 9th Dec 2007 06:55 AM
vba equivalent John Microsoft VB .NET 7 3rd Dec 2007 06:57 PM
what the c# equivalent of ... =?Utf-8?B?am9zZSBnLiBkZSBqZXN1cyBqciBtY3AsIG1jZGJh Microsoft C# .NET 5 31st Jul 2005 03:16 PM
Equivalent of GetPrivateProfileString equivalent in C#? Germic Microsoft C# .NET 1 24th Jan 2005 10:22 AM
C#'s equivalent of the stl Boogie El Aceitoso Microsoft C# .NET 3 6th Apr 2004 03:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:10 PM.