Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C# Structs
#1
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#?
Reply
#2
Code:
struct MyStruct
{
   public int Blah;  
}
Reply
#3
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?
Reply
#4
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?
Reply
#5
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.
Reply
#6
Can't you just add the two integers together and then convert that into a string?

String Blah1 = Num1.ToString()
Reply
#7
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?
Reply
#8
Code:
txtTest.Text = CStr(Total);
Reply
#9
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.
Reply
#10
Really? You can't use CStr in C#? What a load of bull.
Reply
#11
int in C++ means initialize not integer. I'm pretty sure it means that in c# too.
Reply
#12
Nope. int (C#) = Integer (VB).
Reply
#13
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++...
Reply
#14
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";
  }
Reply
#15
Thanks.. I had no clue Smile
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)