Skip to content

Latest commit

 

History

History
82 lines (59 loc) · 2.57 KB

File metadata and controls

82 lines (59 loc) · 2.57 KB
title Variables and Unsigned Integers
actions
checkAnswer
hints
material
editor
language startingCode answer
c#
public class AlienFinder : SmartContract { public static void Main (string alienName) { // enter answer here } }
public class AlienFinder : SmartContract { public static void Main (string alienName) { ulong randomNumber; uint xna; } }

Tag: C# Basics

NEO's smart contract compiler supports a subset of the C# language. This means that when writing C# contracts for NEO, some variables and features of the lanugage are not supported. As we go deeper in the tutorial, we will touch on these limitations.

Variables

Here is an example of some supported variable declarations:

uint unsignedInt = 3281;
ulong unsignedLong = 847282; 
byte b = 23; 
bool condition = true; 

uint is a 32-bit unsinged integer with value ranging from 0 to 4,294,967,295. It can also be declared as uint32

ulong is a 64-bit unsigned integer with value ranging from 0 to 18,446,744,073,709,551,615. It can also be declared as uint64

byte is an 8-bit unsigned integer with value ranging from 0 to 255. It is the smallest unit of integer type. It can also be declared as uint8.

bool is a boolean value, which can either be true or false.

Unsupported Variables:

float a = 3.1415;
double b = 6.0221;
decimal c = 6.6261; 

float double decimal are all floating point variables, and they are not supported natively in NEO Contracts. There are other ways to represent these data types in NEO, which we will cover later in the tutorial.

String in NEO Contracts

Variables and Unsigned Integers You can declare strings in the same way that you can with uint.

string cookingMethod  = "Poached"; 
string food = "Egg"; 

And all basic operations with strings such as concatenation, fetch length and taking substrings is supported for ASCII characters only.

Examples:

string combined = cookingMethod + " " + food;  // "Poached Egg"
string combined2 = $"{cookingMethod} {food}"; //"Poached Egg"
int length = cookingMethod.Length;          // 7
string subString = cookingMethod.Substring (2); // "ached"
string subString2 = cookingMethod.Substring (2,3); // "ach"

Instructions:

  • Within the Main method, declare two variables. One randomNumber of type ulong, and one xna of type uint. (We will learn more about how to generate these numbers in Chapter 7)