|
Vikram A Punathambekar wrote:
I wanted to say, that I understood it, but recomended an other solution!
All the best,
Martin
|
|
|
|
|
Hello.
Here is what you were searching for.
Again I don't recomend it!
string actstring ="Dog";
FancyAnimal actAnimal = (FancyAnimal)Enum.Parse(typeof(FancyAnimal), actstring, true);
Be aware that it will throw an exception if it has no member of that fits!
All the best,
Martin
|
|
|
|
|
Thanks.
A man's gotta' do what a man's gotta' do. Even if it's not recommendable.
|
|
|
|
|
blackjack2150 wrote: A man's gotta' do what a man's gotta' do. Even if it's not recommendable.
But safety first, my friend.
You could validate the string, if you get all the members of the Enum and store it:
string[] members = Enum.GetNames(typof(FancyAnimal));
System.Collections.Specialized.StringCollection memberscollection = new System.Collections.Specialized.StringCollection();
memberscollection.AddRange(members);
Than just make the check:
string act ="dog";
if(memberscollection.Contains(act))
{
Hope it helps!
All the best,
Martin
|
|
|
|
|
Schweet.
Why do you not recommend it? Because of the exception it could throw, or because it's slow?
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Vikram A Punathambekar wrote: Why do you not recommend it? Because of the exception it could throw, or because it's slow?
No, just imagen that.
Software 1:
public enum FancyAnimal
{
dog= 0,
cat= 1,
squirel= 2,
}
text "squirel" is stored in db.
Than in Software 2:
public enum FancyAnimal
{
dog= 0,
cat= 1,
squirrel= 2,
}
No good!
All the best,
Martin
|
|
|
|
|
I assume you're trying to highlight the misspelling of Squirrel?
If the apps are unrelated, it doesn't make sense to make them share the same DB table for storage. Personally, I would go for a readable representation like Dog rather than 0 in the database.
I like your suggestion for a different reason - the code is simpler. I guess I could store the 0 along with Dog in the database and use that mapping.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
Hello,
Vikram A Punathambekar wrote: I assume you're trying to highlight the misspelling of Squirrel?
Exactelly!
Vikram A Punathambekar wrote: If the apps are unrelated, it doesn't make sense to make them share the same DB table for storage.
Sorry, for my bad example!
I off course ment:
YourProgramm Version 1:
and
YourProgramm Version 2:
Vikram A Punathambekar wrote: Personally, I would go for a readable representation like Dog rather than 0 in the database.
As a customer, I would be pretty pissed if I had to fill in my formulars again after a software update!
Only because there was a missspelling found in the code!
All the best,
Martin
|
|
|
|
|
Hi All,How can I create TreeView Control in WebForm.Im using ASP.Net1.1v.
Help me,please.Thank You in advance..
Hi,Im Razana
|
|
|
|
|
Hi Razana,
You can use the Internet Explorer Webcontrols of Microsoft for this. They add 3 more controls for you to use in ASP.Net 1.1 (I have blogged about the tabcontrol[^]).
You can download them Here[^].
Cu
Sven Cipido
|
|
|
|
|
can i save a graphich(ex rectangle) with DrawRectangle(bla...bla...) into some variabel ??
thx
Beginner C#
Yogyakarta - Indonesia
|
|
|
|
|
i think u can store the objects in form of binary file
rahul
|
|
|
|
|
i want a windowsservice which generates crystalreport in pdf automatically at regular duarations and mail has to send ..ex: i want to generate report automatically at 30 or 31st of everymonth and after generation it has to send mail itself automatically.can u please anybody help me out
rajesh m
|
|
|
|
|
thanks to all who help...
1)How do i read a 2 byte, 4 byte, or 8 byte value? I know how to read a one byte, but that only goes up to 255...
2)If any of you are familiar assembly, i need know now how to change (write) to an addresses hex dump, also known as Array of Byte (in most memory editing engines).
3) Reading/writing to a pointer I.E (0x1009624, offset: 0xb14), or any other pointer...
thanks in advanced
|
|
|
|
|
|
I am unable to figure out how to use the get-set style public properties to manipulate the private arrays of that class?
for example
public class Patient
{
private string[] m_labValues
//this is what i am clueless about.
//how do i get down to elements of this array?
//i am sure that this implementation is wrong.
public string LabValues
{
get { return m_labValues; }
set { m_labValues = value; }
}
}
from my main class i desire an ability to directly manipulate the
elements...like:
private Patient patient = new Patient();
patient.LabValues=new String[6];
patient.LabValues[0]="B.P is 120,80";
patient.LabValues[1]="Blood Sugar is 160"
..
..
..
I'm totally clueless about implementing this.
I understand that if i declare the m_LabValues itself as public, i will be able to manipulate it
directly with out using the get-set style
Can some one please help me?
dnahelix
|
|
|
|
|
You need to give your class an "indexer."
public class Patient
{
private string[] m_labValues;
public Patient(int labValueCount)
{
m_labValues = new string[labValueCount];
for(int i = 0; i < m_labValues.Length; i++)
{
m_labValues[i] = string.Empty;
}
}
public string this[int index]
{
get
{
return m_labValues[index];
}
set
{
m_labValues[index] = value;
}
}
}
private Patient patient = new Patient(6);
patient[0] = "B.P is 120,80";
patient[1] = "Blood Sugar is 160";
Error checking omitted for brevity's sake.
|
|
|
|
|
You could simply do the following:
public string[] LabValues
{
get { return m_labValues; }
set { m_labValues = value; }
}
}
This will work but is not considdered good coding. You should rather use a generic list or a public method to set the array.
public void SetLabValues(string[] ar)
{
m_labValues=ar;
}
|
|
|
|
|
try to read on "Indexers" in c#
leslie sanford gave an example of it also
|
|
|
|
|
I thank you all for your kind help. Leslie Sanford's example looks wonderful. I shall implement this and see. Thanks again
dnahelix
|
|
|
|
|
Hi,
dnahelix wrote: public string LabValues
{
get { return m_labValues; }
set { m_labValues = value; }
}
If you want the array m_labValues as a property, you must include the [] in its type:
public string[] LabValues {...}
That way your statements
patient.LabValues[0]="B.P is 120,80";
patient.LabValues[1]="Blood Sugar is 160";
are OK
If there is only one string array to expose (make publicly available) you could work
with an indexor, as others already told you; but for more than one array, that becomes
difficult since an indexor always uses the class name (in the ouside world) and this
(within the class intself), so the only way to differentiate is by the type of the index
variable, which does not have to be an int at all (it could be a string, or whatever
you like), but would be an int if it really stands for an index in an array.
|
|
|
|
|
(c/s c#)
In the mian window, I create a combox that is named axPageLayoutControl1,
I want to use the combox in the child wondows, how can I do ?
in the child wondows, I write it :
if(axPageLayoutControl1.Text!=null)
{
........
this.IbIPrinterName.Text=pPaper.PrinterName;
}
but the axPageLayoutControl1 could not find.
Give me a example ,please
|
|
|
|
|
Hello,
The point is that you can only have access to public members of your mainwindow from your childwindow.
But only if you have the reference of the mainwindow in the childwindow.
Using static fields is not good style, for that problem, but can be usefull in other tasks.
You could pass the reference of mainwindow to the childwindow over the childwindows constructor, or a property.
As it i bad style to make the whole combobox public, you should create methods or properties in your mainwindow, which return the informations you need.
Like:
public string PrinterNameText
{
get
{
if(axPageLayoutControl1!=null)
{
return axPageLayoutControl1.Text;
}
return string.Empty;
}
}
An other solution would be, using delegates.
There you have the luck, that Colin Angus Mackay wrote this fine article[^], which will help you.
Actually, there is also the child to parent connection over the reference, explaint.
All the best,
Martin
-- modified at 1:54 Friday 6th July, 2007
|
|
|
|
|
Either change the access modifier from private to public
or implement a property.. that get/sets the combobox control
|
|
|
|
|
I am trying to make a generic form that has a datagridview on it. I want to be able to send in multiple types of collections, the type will be determined at runtime, to the form to be bound to the datagridview. Im guessing I need to use generics for this, but Im not sure how to do it.
thanks
|
|
|
|