473,396 Members | 2,039 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.

how can I convert this snippet to c#-please help

How can I change the following code to the equivalent in C#

Public Class EventSink : Implements IListEventSink

Public Sub OnEvent(ByVal listEvent As Microsoft.SharePoint.SPListEvent)
Implements Microsoft.SharePoint.IListEventSink.OnEvent

On Error Resume Next

.........

End Class 'EventSink

End class


thanks for your time
Nov 16 '05 #1
5 3859
Reza wrote:
How can I change the following code to the equivalent in C#

Public Class EventSink : Implements IListEventSink

Public Sub OnEvent(ByVal listEvent As Microsoft.SharePoint.SPListEvent)
Implements Microsoft.SharePoint.IListEventSink.OnEvent

On Error Resume Next

.........

End Class 'EventSink

End class


C# has no On Error Resume Next. Rather it has structured error handling
through the use of try/catch/finally. But basically the C# code would
look like:

class EventSink : Microsoft.Sharepoint.IListEventSink
{
public void OnEvent(Microsoft.SharePoint.SPListEvent listEvent)
{
...
}
}
--
Tom Porterfield
Nov 16 '05 #2
Doesn't On Error Resume Next mean: "when I encounter an error, just
continue, pretending the error never happened"??

Wouldn't this be done in C# by catching the error without throwing it?? Like
this:

class EventSink : Microsoft.Sharepoint.IListEventSink
{
public void OnEvent(Microsoft.SharePoint.SPListEvent listEvent)
{
try
{
...
}
catch
{
//do nothing with the caught error
}
}
}
"Tom Porterfield" <tp******@mvps.org> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Reza wrote:
How can I change the following code to the equivalent in C#

Public Class EventSink : Implements IListEventSink

Public Sub OnEvent(ByVal listEvent As Microsoft.SharePoint.SPListEvent) Implements Microsoft.SharePoint.IListEventSink.OnEvent

On Error Resume Next

.........

End Class 'EventSink

End class


C# has no On Error Resume Next. Rather it has structured error handling
through the use of try/catch/finally. But basically the C# code would
look like:

class EventSink : Microsoft.Sharepoint.IListEventSink
{
public void OnEvent(Microsoft.SharePoint.SPListEvent listEvent)
{
...
}
}
--
Tom Porterfield

Nov 16 '05 #3
<top posting continued>
Seems to me that to recreate an "On Error Resume Next" in C#
you would surround each and every line [that could produce an exception]
with a try/catch block
that is:
try { one statement; } catch (Exception e) { // do nothing)
try { next statement; } catch (Exception e) { // do nothing }

"spmm#" <sp******@yahoo.com> wrote in message
news:41***********************@news.xs4all.nl...
Doesn't On Error Resume Next mean: "when I encounter an error, just
continue, pretending the error never happened"??

Wouldn't this be done in C# by catching the error without throwing it?? Like this:

class EventSink : Microsoft.Sharepoint.IListEventSink
{
public void OnEvent(Microsoft.SharePoint.SPListEvent listEvent)
{
try
{
...
}
catch
{
//do nothing with the caught error
}
}
}
"Tom Porterfield" <tp******@mvps.org> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Reza wrote:
How can I change the following code to the equivalent in C#

Public Class EventSink : Implements IListEventSink

Public Sub OnEvent(ByVal listEvent As Microsoft.SharePoint.SPListEvent) Implements Microsoft.SharePoint.IListEventSink.OnEvent

On Error Resume Next

.........

End Class 'EventSink

End class


C# has no On Error Resume Next. Rather it has structured error handling
through the use of try/catch/finally. But basically the C# code would
look like:

class EventSink : Microsoft.Sharepoint.IListEventSink
{
public void OnEvent(Microsoft.SharePoint.SPListEvent listEvent)
{
...
}
}
--
Tom Porterfield


Nov 16 '05 #4
Scot McDermid wrote:
<top posting continued>
Seems to me that to recreate an "On Error Resume Next" in C#
you would surround each and every line [that could produce an exception]
with a try/catch block
that is:
try { one statement; } catch (Exception e) { // do nothing)
try { next statement; } catch (Exception e) { // do nothing }


Exactly. On Error Resume Next means to continue processing no matter
which line of code generates the error. To reproduce that exact
behavior in C# you would have to try every line of code and do nothing
with the caught exception. You could shorten your coding slightly by
using a parameterless catch. Ex:

int x = 0;
try {int y = 1/x;}catch{}
try {Console.WriteLine("{0}", 1/x);}catch{}
try {Console.WriteLine("this is painful");}catch{}

When you see it that way it augments how it is almost always bad idea to
use On Error Resume Next in VB.
--
Tom Porterfield
Nov 16 '05 #5
(Didn't you post this somewhere else?)
Our VB.NET to C# converter, Instant C#, gives:

public class EventSink : IListEventSink
{

void
Microsoft.SharePoint.IListEventSink.OnEvent(Micros oft.SharePoint.SPListEvent
listEvent)
{
OnEvent(listEvent);
}
public void OnEvent(Microsoft.SharePoint.SPListEvent listEvent)
{

//TODO: INSTANT C# TODO TASK: The 'On Error Resume Next' statement is
not converted by Instant C#:
On Error Resume Next

.........;

}

Note that it is highly impractical to convert "On Error Resume Next".
As the others have indicated, you would need try/catch around every
line within the scope of the On Error Resume Next.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: flyaflya | last post by:
a = "(1,2,3)" I want convert a to tuple:(1,2,3),but tuple(a) return ('(', '1', ',', '2', ',', '3', ')') not (1,2,3)
3
by: Heiko Vogel | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hi newsgroup, can anybody tell me, why the following code snippet won't compile: double **ptr; double const ** const c_ptr =...
6
by: clintonG | last post by:
This code has to go into the global.asax Application_Start code block. I'm just not getting this one right and the web-based code converters choke on it. Can somebody rewrite this VB snippet to C#...
6
by: Jim Stools | last post by:
How do I do this: result needs to be a decimal to 2 places? I get casting problems on the below: double myPrice = 1200.125;double myShares = 354.288; decimal myTotal; myTotal = myPrice *...
5
by: nil | last post by:
hello everyone can any one tell me how can i convert my grid data in to pdf?pls provide some code snippet or some link that contains the related topic.. Thanks & Regards, Nil
4
by: tshad | last post by:
I am trying to convert a string character to an int where the string is all numbers. I tried: int test; string stemp = "5"; test = Convert.ToInt32(stemp); But test is equal to 53.
0
by: pleaser | last post by:
hey all, found this nice snippet of code to convert between 2 google map tile types, from satellite to map images. My problem is that the code is written in python, a language I cannot fully read....
3
by: Academia | last post by:
in vs2005 I added a reference to component name "tom" from riched20.dll. In vs2008 I now get the warning: Type library importer could not convert the signature for member DISPPARAMS.rgvar The...
4
by: tshad | last post by:
I was watching a video that used a code snippet to create a property and when you type "prop" tab tab, it would create the private variable as well as the property definitions with the private...
9
by: myotheraccount | last post by:
Hello, Is there a way to convert a DataRow to a StringArray, without looping through all of the items of the DataRow? Basically, I'm trying to get the results of a query and put them into a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
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,...
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
jinu1996
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...
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...
0
isladogs
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...

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.