473,394 Members | 1,642 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,394 software developers and data experts.

C# to VB Translation problem (Is this a singleton?)

I'm getting a little confused here. I have a C# class that I'm trying to
translate to VB.

The C# class is essentially:
public static class Class1
{
..... some private static variables and public static properties.
}

The translation (from several different translation programs) is:
Public NonIneritable Class Class1
private sub New()
End sub
.... some private shared variables and public shared properties
end Class

Does this look right? Just want a second opinion.

(I'm pretty sure the VB version is a singleton but not so sure about the C#
version.)
Aug 28 '08 #1
1 1483
On 2008-08-28, B Chernick <BC*******@discussions.microsoft.comwrote:
I'm getting a little confused here. I have a C# class that I'm trying to
translate to VB.

The C# class is essentially:
public static class Class1
{
.... some private static variables and public static properties.
}

The translation (from several different translation programs) is:
Public NonIneritable Class Class1
private sub New()
End sub
... some private shared variables and public shared properties
end Class

Does this look right? Just want a second opinion.

(I'm pretty sure the VB version is a singleton but not so sure about the C#
version.)
The translation is accurate. In C#, a static class is essentially equivalent
to a VB.NET module - in that it can only have static (vb.net shared) memebers.
Before C#v2, you would declare such a class as:

public sealed class Class1
{
private Class1(){};

// now only add static members
}

Which is essentially what you showed in the VB.NET code. This was a common
enough patter that in C#v2 they started allowing static to be applied to a
clas declaration - which gave compiler enforcement to the above pattern.
Since, you can add not static members to the above C# class.

I wouldn't really call that a Singleton... Though, I suppose it could be
thought of that way :) Usually, you'll see an implementation similar to this
for a singleton:

public class Singleton
{
private static Singleton instance = new Singleton();

private Singleton() {}
public Singlton Instance
{
get
{
return instance;
}
}

// public members
}
Which in VB.NET would look like:

Public Class Singleton
Private Shared _instance As New Singleton()

Private Sub New()
End Sub

Public ReadOnly Property Instance As Singleton
Get
Return _instance
End Get
End Property

' other public members...
End Class

HTH

--
Tom Shelton
Aug 28 '08 #2

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

Similar topics

7
by: Tim Clacy | last post by:
Is there such a thing as a Singleton template that actually saves programming effort? Is it possible to actually use a template to make an arbitrary class a singleton without having to: a)...
10
by: E. Robert Tisdale | last post by:
Could somebody please help me with the definition of a singleton? > cat singleton.cc class { private: // representation int A; int B; public: //functions
1
by: Jim Strathmeyer | last post by:
So I'm trying to implement a singleton template class, but I'm getting a confusing 'undefined reference' when it tries to link. Here's the code and g++'s output. Any help? // singleton.h ...
3
by: Alicia Roberts | last post by:
Hello everyone, I have been researching the Singleton Pattern. Since the singleton pattern uses a private constructor which in turn reduces extendability, if you make the Singleton Polymorphic...
3
by: Harry | last post by:
Hi ppl I have a doubt on singleton class. I am writing a program below class singleton { private: singleton(){}; public: //way 1
5
by: Pelle Beckman | last post by:
Hi, I've done some progress in writing a rather simple singleton template. However, I need a smart way to pass constructor arguments via the template. I've been suggested reading "Modern C++...
3
weaknessforcats
by: weaknessforcats | last post by:
Design Pattern: The Singleton Overview Use the Singleton Design Pattern when you want to have only one instance of a class. This single instance must have a single global point of access. That...
4
by: aaragon | last post by:
Hello everyone, I have this problem that is driving me crazy! I have a typedef for a singleton object in a file "fileA.h", then I try to use that object in "fileB.h" and then the compiler says...
3
by: stevewilliams2004 | last post by:
I am attempting to create a singleton, and was wondering if someone could give me a sanity check on the design - does it accomplish my constraints, and/or am I over complicating things. My design...
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
0
BarryA
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
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,...
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...

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.