Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Twinny · Jul 10, 2013 at 11:11 PM · js-c#js - c#

javascript > c# conversion help

i've looked through the page on syntax differences but i can't for the life of me figure out how to convert this.

 public function get itemNA () : String

i assumed it would be string = get itemNA () but that and a bunch of other variations i tried aren't working.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image InfiniBuzz · Jul 10, 2013 at 11:14 PM 0
Share

it would be:

 public string getItemNA()
 {
    // code
 }

you cannot have spaces in function names. You also cannot assign something to a system type.

the syntax in c# goes like:

 <visibility> <return type> <name>(<parameters>)
 {
     <function code>
 }
avatar image InfiniBuzz InfiniBuzz · Jul 10, 2013 at 11:20 PM 0
Share

Ah if you are looking for property declaration, @flaviusxvii's answer might help you ;)

avatar image aldonaletto · Jul 10, 2013 at 11:53 PM 0
Share

This looks like a property declaration - take a look at @flaviusxvii answer. In JS, a property can be declared inside a class declaration like below:

 class Data {
     var _health: int = 100;
     var _hasRifle = false;
     var _hasPistol = false;
     function get health(): int { return _health; }
     function set health(value: int) { _health = value; }
     function get hasRifle(): boolean { return _hasRifle; }
     function set hasRifle(value: boolean) { _hasRifle = value; }
     function get hasPistol(): boolean { return _hasPistol; }
     function set hasPistol(value: boolean) { _hasPistol = value; }
 }
 
 var data: Data = new Data();
 
 function Start(){
     data.health = 50;
     data.hasRifle = true;
     print("Health = "+data.health+" Has Rifle = "+data.hasRifle);
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by flaviusxvii · Jul 10, 2013 at 11:17 PM

That "get" keyword essentially allows you to call a function but treat it like a member variable. Here is the equivalent setup in C#

 public class Person
 {
     //default constructor 
     public Person()
     {
     }
 
 
     private string _Name;
     public string Name
     {
         //set the person name
         set { this._Name = value; }
         //get the person name 
         get { return this._Name; }
     }
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Twinny · Jul 11, 2013 at 12:23 AM 0
Share

the way you formatted that is sort of confusing. here is the entire function im trying to convert

 public function get itemNA () : String
 {
      return itemName;
 }

i just need to know how this would look in C#. i don't think its neccessary to post the entire class though there is a "private string itemName" i declared at the top of it.

avatar image flaviusxvii · Jul 11, 2013 at 02:47 PM 0
Share
 public string itemNA
 {
     get { return itemName; }
 }

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Create a guitexture When clicked on 3d text? 0 Answers

js to C# converstion Problem 3 Answers

.js to C# conversion 4 Answers

Convert js to C# Serializer problem 1 Answer

How would i convert this from JS into C#? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges