What is "VB.NET My" equivalent in C#?

G

Guest

Hi,

In VB.NET there is a keyword called "My" which has a lot of properties
collected at it.

Is there any equivalent to this "My" in C#?

Thank you.
 
G

Guest

"this" is the keyword used to access the class or struct that the code is
being called from. The same rules apply, in that you can only make references
to the object if it is an instance member (not static (Shared in VB)).
 
F

Frank Rizzo

Mr said:
"this" is the keyword used to access the class or struct that the code is
being called from. The same rules apply, in that you can only make references
to the object if it is an instance member (not static (Shared in VB)).

You are confusing Me and My. Me == this. However, there is no
equivalent to My in c#. It's a VB 2005 only thing.
 
T

Tom Spink

Mr said:
"this" is the keyword used to access the class or struct that the code is
being called from. The same rules apply, in that you can only make
references to the object if it is an instance member (not static (Shared
in VB)).

Unfortunately, "My" is not the same as "this". In VB .NET it's
actually "Me" that is the equivalent to "this".

"My" is not available in C# directly.
 
B

Ben Voigt

Mr Icekirby said:
"this" is the keyword used to access the class or struct that the code is
being called from. The same rules apply, in that you can only make
references
to the object if it is an instance member (not static (Shared in VB)).

"this" is equivalent to VB's "Me" keyword, not the My namespace.

"My" is not actually a VB keyword, it is a part of the .NET library that VB
references by default. You should be able to reference the
"Microsoft.VisualBasic" assembly and use the classes in
Microsoft.VisualBasic.Devices
 
G

Guest

My.Computer.Clipboard is just another way to get to
System.Windows.Forms.Clipboard.
My.Computer.FileSystem is just another route to
Microsoft.VisualBasic.FileIO.FileSystem.
My.Computer.Registry is just another route to Microsoft.Win32.Registry.
The rest can be handled via the following support file we use for Instant C#
conversions:
//----------------------------------------------------------------------------------------
// Copyright © 2005 Tangible Software Solutions Inc.
//
// This file provides classes to reproduce most of the My.Computer and My.User
// functionality in VB. Calls to My.Computer.Clipboard,
My.Computer.FileSystem,
// and My.Computer.Registry have been converted where they were referenced.
//
// Note: My.Settings is converted elsewhere to the standard C#
Properties.Settings.
// Note: My.Resources is converted elsewhere to the standard C#
Properties.Resources.
// Note: My.Application calls are redirected to the converted
My.MyApplication.
//----------------------------------------------------------------------------------------

using Microsoft.VisualBasic.ApplicationServices;
using Microsoft.VisualBasic.Devices;
using System.Security.Principal;
using System.Windows.Forms;

namespace My
{
internal static class Computer
{
//Instant C# Notes:
//Calls to My.Computer.Clipboard have been redirected to
System.Windows.Forms.Clipboard
//Calls to My.Computer.FileSystem have been redirected to
Microsoft.VisualBasic.FileIO.FileSystem
//Calls to My.Computer.Registry have been redirected to
Microsoft.Win32.Registry

internal readonly static Audio Audio;
internal readonly static Clock Clock;
internal readonly static ComputerInfo Info;
internal readonly static Keyboard Keyboard;
internal readonly static Mouse Mouse;
internal readonly static string Name;
internal readonly static Network Network;
internal readonly static Ports Ports;
internal readonly static Screen Screen;

static Computer()
{
Audio = new Audio();
Clock = new Clock();
Info = new ComputerInfo();
Keyboard = new Keyboard();
Mouse = new Mouse();
Network = new Network();
Ports = new Ports();
Screen = Screen.PrimaryScreen;

ServerComputer ThisServerComputer = new ServerComputer();
Name = ThisServerComputer.Name;
}
}

internal static class User
{
private static Microsoft.VisualBasic.ApplicationServices.User ThisUser =
new Microsoft.VisualBasic.ApplicationServices.User();

internal static IPrincipal CurrentPrincipal
{
get
{
return ThisUser.CurrentPrincipal;
}
}
internal static bool IsAuthenticated
{
get
{
return ThisUser.IsAuthenticated;
}
}
internal static string Name
{
get
{
return ThisUser.Name;
}
}
internal static void InitializeWithWindowsUser()
{
ThisUser.InitializeWithWindowsUser();
}
internal static bool IsInRole(BuiltInRole ThisRole)
{
return ThisUser.IsInRole(ThisRole);
}
internal static bool IsInRole(string ThisRole)
{
return ThisUser.IsInRole(ThisRole);
}
}
}
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
 
M

Mark Rae

In VB.NET there is a keyword called "My" which has a lot of properties
collected at it.

Is there any equivalent to this "My" in C#?

Not as far as I know...
 
M

Merlin

Is there any equivalent to this "My" in C#?

My is special VB namespace grouping several services that can be
accessed by their own namespace under C#.
But I saw somewhere on the web somebody who wrote a c# classe
simulating "My". But, of course, this not a good practice. "My" is just
creating aliases to classes that are better accessed directly.
 
M

Michael D. Ober

The My classes are one of the big development boosters for beginning VB 2005
programmers (not necessarily beginning programmers, just those who are new
to VB 2005). They provide wrappers to various parts of the framework,
sometimes with a simple wrapper, but also sometimes with significant code
behind them. The more complex wrappers make the My classes worth using,
especially if they do in a single line what would take half a page or more
of framework calls.

Mike Ober.
 
G

Guest

Actually, the equivalent code is rarely longer. The benefit of "My" is that
it's an easier way for beginners to find certain functionality since they can
navigate via intellisense easier starting with "My" to find what they want.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
 

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

Similar Threads


Top