Results 1 to 3 of 3

Thread: What is the equivalent of static from VB.Net in C#

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2020
    Posts
    1

    Question What is the equivalent of static from VB.Net in C#

    Please help me to know equivalent of static from VB.Net in C#

    Thanks
    Jayachandra

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: What is the equivalent of static from VB.Net in C#

    Usually it is shared. E.g.:
    Code:
    public class Foo
    {
        public static string Bar()
        {
            return "bar";
        }
    }
    Fiddle: https://dotnetfiddle.net/Bo7TJw

    Translates to:
    Code:
    Public Class Foo
        Public Shared Function Bar() As String
            Return "bar"
        End Function
    End Class
    Fiddle: https://dotnetfiddle.net/y29zoq
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: What is the equivalent of static from VB.Net in C#

    It's not clear which way you're converting from your question, but if you mean what is the equivalent of VB 'Static' local variables in C#, then there is no equivalent - you have to declare fields (static C# fields for 'Static' locals within Shared methods, and non-static C# fields for 'Static' locals within non-Shared method).
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width