|
To get Msgbox in VB to C#
|
|
|
|
|
Would be nice if you formulated a real question next time.
Probably System.Windows.Forms.MessageBox.Show(...) is what you are searching for.
|
|
|
|
|
Hi, can someone please tell me how to send a struct to a different class file.
In the other class file (receiving end) you have to specify the type that is sent to it. What must I put there, 'struct' doen't work.
|
|
|
|
|
use the struct name which you have defined not the struct keyword.
|
|
|
|
|
Hard to understand your question but I'll try it:
public struct MyStruct {
}
public class MyClass2 {
private MyClass1 _myClass1;
public void DoSomething() {
_myClass1.Send(myStruct);
}
}
public class MyClass1 {
public void Send(MyStruct myStruct) {
}
}
You have to use the name of the structure (the same as if you would use a normal class).
|
|
|
|
|
Works if both classes are in the same file, but I want to do it between 2 different
files.
//DrawGraph.cs
public partial class DrawGraph
{
public struct Data
{
public int a;
}
public void DoSomething()
{
Draw draw = new Draw(); //Create an instance of Draw.cs class file
Data data = new Data(); //Create an instance of Data struct
data.a = 5;
Image1.ImageUrl = draw.DrawGraph2(data); //Sending struct to Draw.cs class,DrawGraph2 method
}
}
//Draw.cs
public class Draw
{
public String DrawGraph2(@Data@ data) // what must I put between the @ signs
{
String img = "whatever";
return img;
}
}
|
|
|
|
|
try
using namespace1(in the second file)
in datatype
use DrawGraph.data
|
|
|
|
|
Gives me:
The type or namespace name 'namespace1' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DrawGraph' could not be found (are you missing a using directive or an assembly reference?)
I want to send about 30 variables through the struct, coz with struct its easy and nice to access or change the values of variables.
I've read somewhere that its not good to send too much through a struct.
Should I just send the variables directly then?
|
|
|
|
|
Substitute "namespace1" with the name of the namespace containing the struct.
If the namespacec are in different assembplies, you also have to add a reference to the assembly containing the struct.
---
b { font-weight: normal; }
|
|
|
|
|
nm
Thanking You.
Sincerely,
VIRAL PATEL
|
|
|
|
|
VanEtienne wrote: Works if both classes are in the same file, but I want to do it between 2 different
files.
as long as the struct is declared as public it should be no problem. same syntax / method as passing a class an instance of another class.
|
|
|
|
|
These new generic collections are great but do I have to type things like this
Dictionary<DateTime, Dictionary<long, IValueGridCellData>>
over and over again or can I assign another name to the above like c++'s typedef?
|
|
|
|
|
|
|
Thanks mate
|
|
|
|
|
Hi, Can you suggest me any good code generator Wizard for C# which will ask questions about Database and then generate code !! I know there are lots of them available but I am not sure which one is the best as all of them are very expensive, so as I will have to pay, i would like to pay for the best one.
|
|
|
|
|
|
You did not provide me the link to the one you wrote ! If that is free, I can try.
|
|
|
|
|
|
Howdy folks,
I was developing a small db app with C# and ran into a bizarre error. VS told me I was missing curly braces where I was not missing them. I went through and matched up the curly braces several times. What I did notice was when I collapse blocks of code using the gray boxes on the left hand side of the editor that the two braces I got errors on were not aligned correctly with the horizontal gray lines on the left hand of the screen. Not sure if that evens makes sense. The curly braces are fine but it seems that I am getting the errors because of how they match up with the guides on the side of the screen. What can I do to change that? Any ideas? Thanks
paul
|
|
|
|
|
You can post the code segment here, we can see and figure out if really there is missing something.
|
|
|
|
|
Hi,
I tried to use a default value of a parameter in a method like this,
public void myMethod(bool value=false)
{
}
But, I got error saying "Default parameter is not permitted". I was wondering why it is not permitted, then MUST I have to Overload the method with another copy of the method definision ?
|
|
|
|
|
Yes you have to. C# doesn't support default parameters. This[^] FAQ entry explains why.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
thanks Senthil for the article link.
|
|
|
|
|
you could do something like the following;
class ParameterClass
{
public string Name;
public int IDNumber;
public ParameterClass()
{
//set some default values;
//since both fields are public they can
//be overridden if necessary
this.Name = "";
this.IDNumber = 0;
}
}
class OptionalParameters
{
[STAThread]
static void Main(string[] args)
{
//instantiate a parameter class object
//and override the name field
ParameterClass c = new ParameterClass();
c.Name = "Lamont Adams";
optionalObject(c);
//show that the changed ID came back
Console.WriteLine("c.IDNumber={0}",c.IDNumber);
//call the method with only defaults
optionalObject(new ParameterClass());
//pause so we can see the output
Console.ReadLine();
}
public static void optionalObject(ParameterClass arg)
{
//because the parameters received are encapsulated
//in an object, they are all optional but have
//a valid state even if not explicitly set by the caller
Console.WriteLine("arg.Name={0}, arg.IDNumber={1}", arg.Name, arg.IDNumber);
//change one of the field values
arg.IDNumber = 10;
}
}
this way you don't have to have an overload for every single combination of parameters.
hope this helps...
|
|
|
|