|
It's called a ternary operation, and is the shortcut of doing this:
int z = 0;
int x = 1;
int y = 2;
if (x==y)
{
z = x;
}
else
{
z = y;
}
z = (x ==y) ? x : y;
Many high-browed programmers don't like it, but as long as you keep it to just one comparison instead of stacking them, I think it's an acceptable coding practice.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Right, it should not be abused; I would not use it as z = (x ==y) ? x : y; , because an if statement would work for that.
One situation I use it in is something like this:
string.Format
(
"{0} record{1} processed."
,
count
,
count==1?"":"s"
) ;
I find this more readable than the alternatives.
Whenever I see an application write something like, "1 records processed", I . Come on, guys, use the ternary operator!
|
|
|
|
|
hi...
If "a" is true then return value is "b"
else return value is "c"
EXAMPLE::
int nLargeNo=0, nFirstNo=100,nSecondNo=200;
nLargeNo = (nFirstNo>nSecondNo)?nFirstNo:nSecondNo;
Answer:
value of nLargeNo is 200
|
|
|
|
|
AnyBody Help me...
The .ocx file was registered in system using batch file,
Before run our application.Otherwise device is not supported in our application
If want to run our application in new system, that ocx file must be register now that is explicit.
now what i am want means, The ocx file registered through C# application
And Another important thing that is registered only when first time execution our application.
And further run our application, that registration code must be skip.
Doubt: If registered more than one times in same path or different path, what happened, and affected Operating System or harddisk.
|
|
|
|
|
So, try and create an instance of the control. If it works, the control is already registered. If not, then you can register the control using the Process class and launching the "REGSVR32" command line to register it.
|
|
|
|
|
its a nice idea....
thnks...
|
|
|
|
|
How to use ConfigurationManager to modifying "applicationSettings" section of App.config? Or it there any other way to do same? I have the code to modify "appSettings" section of app.config.
1) To modify key "SApp.Properties.Settings" of "appSettings" section of app.config I used below code::
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = @"D:\app.config";
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings");
section.Settings["SApp.Properties.Settings"].Value = "i23";
config.Save();
2)My App.config has below content::
<?xml version="1.0" encoding="utf-8"?>
<appSettings>
<add key="SApp.Properties.Settings" value="http://2344/soap/services"/>
</appSettings>
<applicationSettings>
<Generate.Properties.Settings>
<setting name="Generate_GeneratePDFServiceService"
serializeAs="String">
<value>http://2435/GeneratePDFService</value>
</setting>
</Generate.Properties.Settings>
</applicationSettings>
|
|
|
|
|
Thomas_Mathews wrote: How to use ConfigurationManager to modifying "applicationSettings" section of App.config
No, you can not. ConfigurationManager does not have an interface to do that. And the reason is based on design principles.
Though, you can use the code to modify the App.config considering it to be a xml file. I would suggest you to store the settings which may be changed using the application in some other Xml file/database.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi.......
U can use ConfigurationManager to modifying "applicationSettings" and also can do the
same by concidering it as a XML file...
Just follow below Link to know more...
About ConfigurationManager
|
|
|
|
|
Hi All,
You can modify value of 'AppSettingsSection' by below code.
ConfigurationSectionGroup sectionGroup = config.SectionGroups["applicationSettings"];
ClientSettingsSection section = (ClientSettingsSection)sectionGroup.Sections["....Settings"];
section.Settings.Get("GeneratePDF...").Value.ValueXml.InnerText = urlname;
config.Save(ConfigurationSaveMode.Minimal, true);
-Thomas
|
|
|
|
|
Dear All,
I have a sequence of hexa decimal values like 5C 8D 45 65 6F 0A without any spaces in between from an input channel.
Now I have to xor the whole decimal value with another hex value for example 4C and has to get the output and perform the operations based on the result.
The sequence of hex values can be of 40 bytes long.
I don't know how to xor the values.
Can any one tell me how to perform the above?
Thanks a lot in advance.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
what dont you hardcord it and just convert all hex values to bits, XOR the binary then rebuild the to hex string
|
|
|
|
|
Dear Musefan,
That I can do. But it has to be done in loop so it will slow down the process that is why I am asking is there any way to implement it easily without degrading the performance of the system.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
well in all fairness i cant image any function would be able to do an XOR without looping through the binary values, how else would you be able to compare bit by bit?
|
|
|
|
|
this not very effiecnt but something along lines should work:
string HexToBinary(string hexString)
{
string result = "";
foreach(char c in hexString)
{
switch(c){
case '0':
result += "0000";
case '1':
result += "0001";
...
case 'F':
result += "1111";
}
}
return result;
}
string BinaryToHex(string binString)
{
string result = "";
for(int i = 0; ; < binString.length / 4; i++)
{
string temp = binString[0] + binString[1] + binString[2] + binString[3];
binString = binString.Substring(4, binString.Length - 1);
switch(temp){
case "0000":
result += "0";
...
case "1111":
result += "F";
}
}
return result;
}
string XORStrings(string s1, string s2)
{
string bin1 = HexToBinary(s1);
string bin2 = HexToBinary(s2);
string result = "";
for(int i = 0; i < bin1.length; i++)
{
if(bin1[i] == bin2[i])
result += "0";
else
result += "1";
}
return BinaryToHex(result);
}
LOL dont even know if will work, plus if your hex string are different lengths you may need to account for that in the XORStrings method, i.e. add 0's to start of bin2 to match bin1 length
|
|
|
|
|
Dear Friends,
Thank you a lot.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
I changed binary2Hex and Hex2Binary parts to make a bit more efficient
I am using the code above at the moment, it is trusted to be worked.
private string HexToBinary(string hexString)
{
string binaryval = String.Empty;
for (int i = 0; i < hexString.Length; i = i + 2)
{
binaryval += Convert.ToString(Convert.ToInt32(hexString.Substring(i, 2), 16), 2).PadLeft(8, '0');
}
return binaryval;
}
private string BinaryToHex(string binString)
{
string hexval = String.Empty;
for (int i = 0; i < binString.Length; i = i + 8)
{
hexval += Convert.ToString(Convert.ToInt32(binString.Substring(i, 8), 2), 16).PadLeft(2, '0');
}
return hexval;
}
private string XORStrings(string s1, string s2)
{
string bin1 = HexToBinary(s1);
string bin2 = HexToBinary(s2);
string result = String.Empty;
for (int i = 0; i < bin1.Length; i++)
{
if (bin1[i] == bin2[i])
result += "0";
else
result += "1";
}
return BinaryToHex(result);
}
|
|
|
|
|
You could convert them to bytes (or ints, or longs, will be faster but you'd have to pad)
Then xor and convert back. Converting hex string into/from ints is pretty fast.
I wouldn't expect "manually" xorring (on characters) to be faster.
|
|
|
|
|
I am attempting to write some code that will execute one of my EXE's from another project.
This other EXE file uses an INI file which is located in the same folder as the exe itself.
But when I run the exe file using C# code, the exe creates a new default INI file here: C:\Documents and Settings\UserName\Local Settings\Application Data\Temporary Projects\KeepAlive\bin\Debug (this is the projects directory)
How do I execute an exe in code asif it was simply a shorcut being double-clicked on the desktop?
I have tried the following:
Process.Start(@ApplicationFullPath);
string str = (@ApplicationFullPath;
Process process = new Process();
process.StartInfo.FileName = str;
process.Start
Both of these solution had the same problem.
|
|
|
|
|
and what is the path of the .exe you want to execute?
|
|
|
|
|
"C:\Program Files\Company\ApplicationPath"
|
|
|
|
|
so just to clarify.
you have an apllication in C:\..\Application that you want to launch an applciation in C:\..\keepAlive\Bin\Debug. The application in debug is supposed to create an INI file in its location but instead it creates it in the location of the application that is loading it? (LOL maybe not so clear)
|
|
|
|
|
Application A -> Located in Program Files, uses a INI file in it's "home directory" (Creates a default INI if none exists)
Application B -> VisualStudio Project has code to startup application A, however, when B starts A, A looks for this INI file in Documents & Setting in the path where Application B's debug binaries etc are located. It doesn't find it and creates a default INI, but not in Program Files.
|
|
|
|
|
Thats because when B starts A, A's startup path is set to B's home directory. Use the following algorithm in B to start A:
1. Change the directory where A resides.
2. Start A
This should solve your problem.
Excuse me for buttin' in, but I'm interrupt driven.
|
|
|
|
|
How do I change the Directory where A resides? A is perfect where it is, I'm not sure what you mean...
|
|
|
|