Mirage Source

Free ORPG making software.
It is currently Tue Apr 16, 2024 4:32 pm

All times are UTC




Post new topic Reply to topic  [ 16 posts ] 
Author Message
 Post subject: C# Structs
PostPosted: Tue Jul 07, 2009 8:57 am 
Offline
Knowledgeable

Joined: Sun Jul 29, 2007 12:23 am
Posts: 199
How do I go about making structures in C#? I know in VB you do like

Code:
Structure MyStruct
    Public Blah As Byte
End Structure

Public LOL As MyStruct


How do I make this in C#?


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Tue Jul 07, 2009 8:07 pm 
Offline
Newbie

Joined: Wed Jul 01, 2009 1:41 am
Posts: 4
Code:

struct MyStruct
{
   public int Blah;   
}



Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Tue Jul 07, 2009 9:32 pm 
Offline
Knowledgeable

Joined: Sun Jul 29, 2007 12:23 am
Posts: 199
Simple enough lol. Now, sometimes it says it cant put a string to a int, so I have to convert it. Im doing Convert.ToInt32() and all that. My question is, what is different about the Convert.ToString() compared to the blah.blah.ToString?


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Tue Jul 07, 2009 9:55 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Jul 24, 2008 6:42 am
Posts: 703
Google Talk: infectiousbyte@gmail.com
Beres wrote:
Simple enough lol. Now, sometimes it says it cant put a string to a int, so I have to convert it. Im doing Convert.ToInt32() and all that. My question is, what is different about the Convert.ToString() compared to the blah.blah.ToString?


Is there no specific data type for strings? I've never really used C# so I'm a bit ignorant, but isn't declaring it as an int declaring it as an integer? Instead would you not declare it as a string?

_________________
Image
GIAKEN wrote:
Since I'm into men, not women

GIAKEN wrote:
I can't take these huge penises anymore! All that's left is shame! And blood


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Tue Jul 07, 2009 10:58 pm 
Offline
Knowledgeable

Joined: Sun Jul 29, 2007 12:23 am
Posts: 199
Well for instance I have a string. But I have 2 integers that I want to add up and add it inside the string. In order to put the total value inside the string, I have to convert the integer into a string. Idk, im new. Im most likely doing it wrong.


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Wed Jul 08, 2009 12:48 am 
Offline
Newbie

Joined: Wed Jul 01, 2009 1:41 am
Posts: 4
Can't you just add the two integers together and then convert that into a string?

String Blah1 = Num1.ToString()


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Wed Jul 08, 2009 1:21 am 
Offline
Knowledgeable

Joined: Sun Jul 29, 2007 12:23 am
Posts: 199
Thats what I have been doing. For example

Code:
int Num1 = 10;
int Num2 = 10;
int Total = 0;

Total = Num1 + Num2;
txtTest.Text = Convert.ToString(Total);


I was just curious about the .ToString part that you can select. Like txtTest.text.ToString. Im situated with that. I guess this will be my C# questions post lol. I know how to create files using the FileStreamer and StreamWriter and all that good stuff, also know how to create binary files now. however, in VB6 I could use App.path & "path". In C#, how do I set a file path just like in VB. More specifically, how to set the file path for stuff thats in the same location as the exe. Besides having to do like @"\C:\blah\blah...." Say I have a folder named Files, inside the same folder as my exe. how do I setup a filepath to that sub folder so I can write files inside of it?


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Wed Jul 08, 2009 3:32 pm 
Offline
Regular
User avatar

Joined: Sun Jun 01, 2008 8:39 pm
Posts: 91
Code:
txtTest.Text = CStr(Total);


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Wed Jul 08, 2009 5:23 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
Toast wrote:
Code:
txtTest.Text = CStr(Total);


That's vb.net. He's asking about C#.

You can use either Convert.ToString() or .ToString(), I think using .ToString() is easier.


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Wed Jul 08, 2009 5:44 pm 
Offline
Regular
User avatar

Joined: Sun Jun 01, 2008 8:39 pm
Posts: 91
Really? You can't use CStr in C#? What a load of bull.


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Wed Jul 08, 2009 7:35 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
int in C++ means initialize not integer. I'm pretty sure it means that in c# too.

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Wed Jul 08, 2009 7:43 pm 
Offline
Regular
User avatar

Joined: Sun Jun 01, 2008 8:39 pm
Posts: 91
Nope. int (C#) = Integer (VB).


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Thu Jul 09, 2009 7:36 am 
Offline
Banned
User avatar

Joined: Mon Jun 05, 2006 9:22 pm
Posts: 394
Location: USA
If you haven't used C# don't speculate please.

I'd say use the following:

Code:
int Num1 = 10;
int Num2 = 10;
int Total = 0;

Total = Num1 + Num2;
txtTest.Text = Total.ToString();


ToString is more common.


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Wed Jul 15, 2009 1:15 am 
Offline
Newbie
User avatar

Joined: Sun Feb 11, 2007 4:08 am
Posts: 10
Labmonkey wrote:
int in C++ means initialize not integer. I'm pretty sure it means that in c# too.

"int" when declaring functions and variables is most definitely an integer datatype within C++...

_________________
Quote:
You never finish a program, you just stop working on it.


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Sun Jul 19, 2009 10:21 pm 
Offline
Pro
User avatar

Joined: Mon May 29, 2006 3:26 pm
Posts: 493
Location: São Paulo, Brasil
Google Talk: blackagesbr@gmail.com
Beres wrote:
My question is, what is different about the Convert.ToString() compared to the blah.blah.ToString?

Convert.ToString() is a bunch of functions from the .Net Framework.
.ToString() is a class member function. The thing is that every type in C# already has the implementation of the ToString function, even your custom classes(the default shows the object name, if I remember correctly). The good thing about this is that you can make your own ToString() functions for your custom classes, using the override reserved word.
Code:
  public override string ToString()
  {
     return "anything";
  }

_________________
http://www.blackages.com.br
Image
Dave wrote:
GameBoy wrote:
www.FreeMoney.com
I admit I clicked. I immediately closed upon realizing there was, in fact, no free money.
Robin wrote:
I love you and your computer.Marry me.


Top
 Profile  
 
 Post subject: Re: C# Structs
PostPosted: Sun Jul 19, 2009 10:45 pm 
Offline
Knowledgeable

Joined: Sun Jul 29, 2007 12:23 am
Posts: 199
Thanks.. I had no clue :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group