Why and what is the purpose of "New" to be used?

HI All,

As i am beginner to UiPath, my doubt with confusion is…
The below is the set of statements which i need clear idea of when and why we need “New” type to be used here… what is it actually…

DateTime birthday=new DateTime(1991,08,27)
New String(){}
Var = new fileinfo(item)

this varieties of “New” can able to see in many places as default also assigning statements and some examples i don’t see :disappointed_relieved:

Please help to correct me for better understanding…
Thanks in Advance !

Welcome to the UiPath community @Anish

That new is a keyword that signifies that a new variable is to be created, it is followed by the variable data type and the parameters if you want to pass.

Below documentation will help you to understand better. Happy learning! :slight_smile:

New Operator - Visual Basic | Microsoft Docs


Welcome to forums

In memory, you can create an object using the “new” keyword

Refer to know how you use in oops concepts in C#

Hope this may help you



Welcome to uipath forum

UiPath is built on Microsoft Windows workflow foundation and on dot net framework

Which means it’s uses vb.net mostly and C# as well

In that case both C# and VB.Net, there are many operators and keywords available.

Where “New” is one of the keywords.

To be very simple,

  • It is used to create empty new object.
  • It allocates the memory at runtime.

If any type of object has to be created in the middle or any place along the workflow then create it with new keyword

Ok now what kind of object gas to be created with new keyword
For your reference,

  1. List - New list(of string)
  2. Array - New Array(of string)
  3. Dictionary - New Dictionary(of string, string)
  4. Datatable - New System.Data.Datatable
  5. Password - New System.Net.NetworkCredentials

Cheers @Anish

we do have

  • simple datatypes e.g. string, int32…
  • complex datatypes like List, DataTable, DateTime …

a simple datatype we can declare (creating the variable within variable panel) and use it directly
a complex datatype we do:

  • declare (similar to simple datatypes)
  • AND intialize afterwards in order to make use of it

For the init step we do use the new keyword e.g. new List(Of String), new DataTable()…

Fazit: complex types will be initialized with new

1 Like

@rahulsharma @Srini84 @Palaniyappan @ppr

Once again Thanks!, for providing your valuable answers in different angles… This made me clear now.:slight_smile:

1 Like