Mirage Source
http://miragesource.net/forums/

C# Structs
http://miragesource.net/forums/viewtopic.php?f=158&t=5928
Page 1 of 1

Author:  Beres [ Tue Jul 07, 2009 8:57 am ]
Post subject:  C# Structs

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#?

Author:  Syntax [ Tue Jul 07, 2009 8:07 pm ]
Post subject:  Re: C# Structs

Code:

struct MyStruct
{
   public int Blah;   
}


Author:  Beres [ Tue Jul 07, 2009 9:32 pm ]
Post subject:  Re: C# Structs

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?

Author:  Nean [ Tue Jul 07, 2009 9:55 pm ]
Post subject:  Re: C# Structs

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?

Author:  Beres [ Tue Jul 07, 2009 10:58 pm ]
Post subject:  Re: C# Structs

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.

Author:  Syntax [ Wed Jul 08, 2009 12:48 am ]
Post subject:  Re: C# Structs

Can't you just add the two integers together and then convert that into a string?

String Blah1 = Num1.ToString()

Author:  Beres [ Wed Jul 08, 2009 1:21 am ]
Post subject:  Re: C# Structs

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?

Author:  Toast [ Wed Jul 08, 2009 3:32 pm ]
Post subject:  Re: C# Structs

Code:
txtTest.Text = CStr(Total);

Author:  Jacob [ Wed Jul 08, 2009 5:23 pm ]
Post subject:  Re: C# Structs

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.

Author:  Toast [ Wed Jul 08, 2009 5:44 pm ]
Post subject:  Re: C# Structs

Really? You can't use CStr in C#? What a load of bull.

Author:  Labmonkey [ Wed Jul 08, 2009 7:35 pm ]
Post subject:  Re: C# Structs

int in C++ means initialize not integer. I'm pretty sure it means that in c# too.

Author:  Toast [ Wed Jul 08, 2009 7:43 pm ]
Post subject:  Re: C# Structs

Nope. int (C#) = Integer (VB).

Author:  James [ Thu Jul 09, 2009 7:36 am ]
Post subject:  Re: C# Structs

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.

Author:  4ngel [ Wed Jul 15, 2009 1:15 am ]
Post subject:  Re: C# Structs

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++...

Author:  Dragoons Master [ Sun Jul 19, 2009 10:21 pm ]
Post subject:  Re: C# Structs

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";
  }

Author:  Beres [ Sun Jul 19, 2009 10:45 pm ]
Post subject:  Re: C# Structs

Thanks.. I had no clue :)

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/