Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Difference between String and String()

Can someone explain the difference between
String type and String() type.


  • PsightoplazmPsightoplazm Member Posts: 332 ✭✭
    From the way you formatted your question I am unable to deterimine what you wanted to know...

    So, there is a "String" type and a "string" type.

    there is actually no difference between these. "string" is merely a keyword that is mapped to the "String" class. If you work where I work the rule is to always use "string" for consistency.

    If what you meant to ask was what it means when you see
    string m = new String();

    then the String() is something called a constructor. In order to instantiate any class you must use a constructor. In most cases the constructor will not need any parameters passed into it so you will just see "new classname()"

    The constructor is always accessed as a method that shares the same name as the class that is being constructed.

    so for example:
    public class Point
    public Point()
    // here is the constructor
  • magenamamagenama Member Posts: 3
    I am following VB.NET class from Programmers
    Heaven website. I coded following code

    Dim sentence As String = "Learning VB.Net"
    Dim split As String() = sentence.Split(New [Char]() {" "c})

    We define sentence As String not String class
    But then we call Split method on sentence

    Shouldn't I define sentence as
    Dim sentence As String() ?
Sign In or Register to comment.