|
I am asking about Windows 8.1 universal app.
For universal app grid app project type is not available.
|
|
|
|
|
hi all!
can someone explain to me the difference between the two equations:
1)v = (u(M1-M2)+(2M2*u))/(M1+M2) (elastic collisions)
2)v= vA + j/MA*n (impulse method)
In physics, are they the same?
thanks!
|
|
|
|
|
Isawyouoo wrote: In physics, are they the same? Ask a physics grad. These forums are for programming issues.
|
|
|
|
|
Equations may look like code, but in practice they are very different.
You need to ask a physicist, not a developer.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi,
I have a string that may contains several hashtags starting with # like this example:
"Hello, I am #Hashtag1 and #Hashtag2"
I want to save those hashtags, as many as they are, in an array.
Can anyone help me how to do it.
Thank you in advance.
|
|
|
|
|
Use a regex to identify them:
\#\w*
You can then use the Regex.Matches to convert them to a collection with Linq methods:
string[] hashtags = Regex.Matches(myDate, @"\#\w*").Cast<Match>().Select(m => m.Value).ToArray();
[edit]Matches, not Match, Griff [/edit]
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 2-Jul-15 15:20pm.
|
|
|
|
|
That should be Regex.Matches , not Regex.Match .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Clearly, I read what I meant to type...
Thanks!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
thank you so much, it worked perfectly
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I have written a 3 by 3 matrix program where I assume that the matrix represents the circle. It is able to tell the coordinates of the axes as well as the origin.
For example a 3 by 3 matrix, it will display these results which are what I want. The program will find the origin automatically by taking the 3 minus by 1 then divide by 2.
Index=[0,0](x,y)=(-38,38)
Index=[0,1](x,y)=(0,38)
Index=[0,2](x,y)=(38,38)
Index=[1,0](x,y)=(-38,0)
Index=[1,1](x,y)=(0,0)
Index=[1,2](x,y)=(38,0)
Index=[2,0](x,y)=(-38,-38)
Index=[2,1](x,y)=(0,-38)
Index=[2,2](x,y)=(-38,-38)
However, when I want to do a 4 by 4 matrix and so on, the result of the coordinates does not match with my calculation. Is there any formula for this?
1 unit=38
4 by 4 matrix would be
Index=[0,0] (x,y)=(-76,76)
Index=[0,1] (x,y)=(-38,76))
Index=[0,2] (x,y)=(0,76)
Index=[0,3](x,y)=(38,76)
Index=[1,0] (x,y)=(-76,38)
Index=[1,1] (x,y)=(-38,38)
Index=[1,2] (x,y)=(0,38)
Index=[1,3] (x,y)=(38,38)
Index=[2,0] (x,y)=(-76,0)
Index=[2,1] (x,y)=(-38,0)
Index=[2,2] (x,y)=(0,0)
Index=[2,3] (x,y)=(38,0)
Index=[3,0] (x,y)=(-76,-38)
Index=[3,1] (x,y)=(-38,-38)
Index=[3,2] (x,y)=(0,-38)
Index=[3,3] (x,y)=(38,38)
Tomorrow, I will post my code because my file is broken and I can only retrieve from my workplace. Please help me.
|
|
|
|
|
Explain your problem properly.
"I have written a 3 by 3 matrix program where I assume that the matrix represents the circle"
What circle? How does a Matrix represent a circle?
"It is able to tell the coordinates of the axes as well as the origin."
Who is able to tell the coordinate of what?
"The program will find the origin automatically by taking the 3 minus by 1 then divide by 2."
3 what? 1 what?
|
|
|
|
|
|
public class User{
public int UserID {get;set;}
public string Username {get;set;}
publict override bool Equals(object obj)
{
if(!(obj is User)) return false;
return (obj as User).UserID == UserID;
}
public override int GetHashCode()
{
return UserID;
}
public override ToString()
{
return Username;
}
}
base on the code above, when i create to object from the database, comparing them will return false even they are the same.
example:
User u1 = new User(){UserID = 1, Username = "FirstUser"};
User u2 = new User(){UserID = 1, Username = "FirstUser"};
var b = u1 == u2;
variable b is false;
I thought they will be the same,
is there i missing there?
I will appreciate for any advice will be given
Thank you.
|
|
|
|
|
You need to override the == and != operators.
public static bool operator ==(User lhs, User rhs)
{
if(lhs == null && rhs == null) return true;
if(lhs == null && rhs != null) return false;
if(lhs != null && rhs == null) return false;
return lhs.UserID == rhs.UserID;
}
public static bool operator !=(User lhs, User rhs)
{
return !(lhs == rhs);
}
Just insert these into the class and you will be able to use == and != to check for equality and inequality.
Note that if you override one, C# forces you to override the other.
There are several other operators you can override. You can get all the nitty gritty details on MSDN[^].
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
thank you for the quick reply.
I thought overriding equals will be enough,
By the way, one more question base on the code above, which is most efficient using the "Equals" method or the equals operator?
Thank you
|
|
|
|
|
|
As you're dealing with a class , not a struct , you can simplify the operator to:
public static bool operator ==(User lhs, User rhs)
{
return Equals(lhs, rhs);
}
public static bool operator !=(User lhs, User rhs)
{
return !Equals(lhs, rhs);
}
The static Equals method[^] will perform the null checks for you, and then call the instance Equals method on the first parameter:
public static bool Equals(Object objA, Object objB)
{
if (objA==objB) {
return true;
}
if (objA==null || objB==null) {
return false;
}
return objA.Equals(objB);
}
At first glance, it might look like the first line of that method would cause a stack overflow, since your == operator is calling a method that calls the == operator. However, within the Equals method, it's calling the == operator on the Object type, which just tests for reference equality.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you, for all the hint, i finally got it now
|
|
|
|
|
You might also want to check for null being passed in to the Equals method.
i.e. insert the following line into the beginning of the method:
if(other == null) return false;
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Hi,
I have an application which is built on .net 2.0 framework. I am looking for command to execute powershell command from c#.
Ex: in Powershell command prompt, we need to type "Install-WindowsFeature XPS-viewer" to enable XPS viewer.
I am looking for C# code to do this. I don't want to use script file.
|
|
|
|
|
|
Hello, I am new in this forum and this time I need your friendly help:
my problem is, that this exception appears when "pathName" is an UNC path name.
public Boolean CheckPathName(string pathName,
FileSystemRights rights,
AccessControlType type)
{
Boolean ok = false;
try
{
_accountName = System.Environment.UserDomainName +
'\\' + System.Environment.UserName;
if (Directory.Exists(pathName))
{
AddDirectorySecurity(pathName, _accountName, rights, type);
ok = true;
}
}
catch (InvalidOperationException ex)
{
throw ex;
}
return ok;
}
public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
{
DirectoryInfo dInfo = new DirectoryInfo(FileName);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(Account, Rights, ControlType));
dInfo.SetAccessControl(dSecurity);
}
can someone help me?
|
|
|
|
|
Don't use throw ex; - it destroys the stack trace, and makes it harder to diagnose the problem.
Either use throw; to rethrow the exception, or remove the try...catch block altogether.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
thank you for your reply.
I changed the code, but result is the same.
try
{
_accountName = System.Environment.UserDomainName +
'\\' + System.Environment.UserName;
if (Directory.Exists(pathName))
{
AddDirectorySecurity(pathName, _accountName, rights, type);
ok = true;
}
}
catch (InvalidOperationException ex)
{
throw;
}
|
|
|
|
|