|
|
I'am guessing that you return some string representation for other types.
Why not use some helper methods:
string ToString(bool b) { return b ? "Yes" : "No"; }
string ToString(object o) { return o.ToString(); }
...
And call this method from your code. At runtime the correct method is called.
For your own classes, override the ToString method to get the correct string representation.
-^-^-^-^-^-
no risk no funk
|
|
|
|
|
After reading the thread about switching on strings I can't help but present this solution:
if(Option is bool)
switch ( Option.ToString() )
{
case "True" : return "Yes" ;
case "False" : return "No" ;
}
But seriously, you probably need a better design.
|
|
|
|
|
I like switching on strings
PIEBALDconsult wrote:
But seriously, you probably need a better design.
Probably. It's a menu system for a game where you can add any options and switch between them (like: "Multisampling: On|Off"
Usually it's fine to just return the ToString() representation of this object, but in case of a "bool" menu item I don't want to return "True" and "False"
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Why on earth, CheckBoxList in windows form doesn't have datasource property.
i just want to bind my checkboxlist with dataset. How am i suppose to do that?
Thanks
|
|
|
|
|
To ratate a rectangle at an angle where angle would not be referenced from default World Cordinate but custom defined reference point.
SHK
|
|
|
|
|
is there a question ?
Get your math equations, and code them inside your Paint handler.
You will need the Math class, with Cos and Sin methods, and Pi constant.
Or you can hide behind the Graphics.RotateTransform method !
And obviously there are lots of CodeProject articles that rotate something.
|
|
|
|
|
Luc Pattyn wrote: is there a question ?
I wondered that myself. I just see a statement that even the Plain English Compiler would have a tough time parsing
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi there,
I have two classes; ClassA and ClassB.
I want that ClassA has an object of classB by which call the methods of ClassB.
like this: objectOfClassB.Methods();
ClassB is an abstract class so it cannot be instantiated.
In other words I want other classes access to ClassB only by its object in ClassA.
How can I afford to do this?
|
|
|
|
|
Majid Shahabfar wrote: I have two classes; ClassA and ClassB.
No, you don't. Nobody gives threir classes stupid names like that. In reality they have better names, that says something about what they are for. By taking away those names and creating phony names, you only make it harder to understand what it is you are trying to do.
Majid Shahabfar wrote: I want that ClassA has an object of classB
As ClassB is an abstract class, you can't create instances of it, so ClassA can not have an instance of ClassB. You have to have a class that inherts from ClassB, so that you can create an instance of that class.
Majid Shahabfar wrote: How can I afford to do this?
You can't. You would have to buy Microsoft, so that you could make them change how the language works, and obviously you can't afford to buy Microsoft.
---
single minded; short sighted; long gone;
|
|
|
|
|
Ok,
Suppose ClassB is not an abstract class.
Now show me a way by which other classes make access to ClassB members only through ClassA. (not directly instantiate an object of ClassB).
|
|
|
|
|
What is it that you are trying to accomplish really?
You can prevent creations of ClassB insteances by making the constructor non-public. If you want to restrict creation of ClassB instances to ClassA, you have to put the two classes in an assembly by themselves, so that you can make the constructor internal.
---
single minded; short sighted; long gone;
|
|
|
|
|
A bit harsh don't you think Guffa?
Freedom is the right to say that 2+2=5 if this is so everything else will follow.
|
|
|
|
|
Hi,
you could make ClassB a private inner class of ClassA, so nothing outside
ClassA would be able to instantiate or otherwise reference ClassB.
Making ClassB "abstract" is irrelevant in this; if you do you need yet another
concrete class that inherits from it.
|
|
|
|
|
Hi guys,
i have a form, which, on mouseclick, opens another form. Half of the time it's all well. But sometimes i get an InvalidOperationException with the message that this can't be done while resizing an automatically filled column.
Now, on the second form there is a gridview, which is filled at the LOAD event.
Creating Form 2:
<br />
FrmPaths f = new FrmPaths();<br />
f.Show(this);<br />
Load event:
<br />
foreach (string s in PathManagment.Directories)<br />
{<br />
dataSet1.Tables["paths"].Rows.Add(new object[] { (s) });<br />
}<br />
Could anybody please help me?
|
|
|
|
|
sounds strange .......
do you get this exception when you are debugging?
if so,
{
then there's no problem
}
else
{
i don't know
}
|
|
|
|
|
yes i got this exception when i was debugging.
i even know where it came from. I had ColumnsHeaderHeigthSizeMode on Auto by mistake. I turned it off and now the problem is gone.
I'd like to understand what the problem is, anyway. Nobody knows?
Btw. why isn't there a problem if i was debugging?
Thank you
|
|
|
|
|
i don't know whats wrong with VS, i have noticed that when im in debugging mode sometimes i get exception but when im running the project normally that when not in debugging mode, it runs fine. and mostly the exeception is null reference exception.
|
|
|
|
|
Ok thank you. That is good to know. I was really desperated.
|
|
|
|
|
and yes i forgot to mention one thing, this type of error usually occurs when you are going to another class/form, like the way you were doing
myform.show()
and in your myform load event you had something n there you get some error
|
|
|
|
|
I'm having the following issue:
i am using "Directory.GetFiles" to retrieve all filenames from a path.
In that path i have filenames which have hebrew characters in them.
I use a debugger to take a close look at the characters that constructs such a filename string and i can see that
the hebrew characters are not REAL char (they are numbers above 1000 - how can that be for char?).
This makes a problem when i try to write the string to a file - the characters looks weird when i open it later with a text editor,
and that is probably because the truly written thing for each char is 2 bytes instead of just one that represents each hebrew character.
How can that be solved?
Thanks.
|
|
|
|
|
Hi,
you can specify which character encoding should be used when writing text to
a file. By default ASCII is used, and non-ASCII characters get mapped onto
ASCII characters somehow (e.g. accents would be dropped); of course for very
different scripts, such mapping makes no sense. You really want a file that
can hold real 16-bit characters where appropriate.
One way of doing this is by using a StreamWriter; one of its constructor
overloads takes an Encoding object, you should consider Encoding.Unicode
BTW: your Hebrew characters are real characters, if Visual shows them as numbers
that's to make sure you can read them (if you're unfamiliar with the script),
and you can paste them like that in an ASCII file. Normally your source files
are ASCII files, taking one byte per character; as soon as you paste a non-ASCII
character in a string literal or so, the file will be saved as a UTF8 or a Unicode
file, and may no longer be readable by other apps.
|
|
|
|
|
Well - using UTF8 with the StreamWriter did the job!
Man - thanks a lot!
|
|
|
|
|
impeham wrote: they are numbers above 1000 - how can that be for char?
You're clearly an ex-C++ programmer. char in C# is not a byte-size quantity as it is in C++, it represents a single UTF-16 encoded value (i.e. it's a synonym for short ). All strings in the .NET Framework are Unicode internally, using UTF-16. Hebrew characters fall in a block between U+0590 and U+05FF, with alef encoded at U+05D0 = 1488.
The default encoding for .NET StreamWriter objects is UTF-8. Alef does indeed turn into two bytes in the output, 0xD7 0X90. If you want to use a different encoding, for example Windows codepage 1255 for Hebrew, you need to create a suitable Encoding object and pass it to the StreamWriter 's constructor.
|
|
|
|
|
i have seen the tags became popular now in many sites and blogs, last i have seen it in the qna.live.com and i want to know to deal with it? is it just a text file or database entry..
can anyone explain tags please..
|
|
|
|