default constructor C# private or public?
Default constructor for C#, if it is not specificed, is private.
you can test it via
public class TestConstructor
{
public string title2 = string.Empty;
string title = string.Empty;
}
you will found that when you
TestConstructor tc = new TestConstructor();
tc.title2 ==> this is valid in the intellisence
tc.title ==> TestConstructor.title' is inaccessible due to its protection level
tc.somethingNotExist ==> TestConstructor does not contain a definition for 'somethingNotExist' and no extension method 'somethingNotExist' accepting a first argument of type 'TestConstructor' could be found (are you missing a using directive or an assembly reference?)
Sunday, June 28, 2015
Friday, June 26, 2015
What is outOfBrowser in Silverlight?
Microsoft's explaination:
https://www.microsoft.com/silverlight/out-of-browser/
Silverlight offers a new set of features for building light-weight, sandboxed companion experiences for the Web that run on the desktop. Silverlight out of browser allows websites to build even closer, persistent relationships with customers. It enables the application to be placed in a restricted store on the user’s machine; and then provide a link directly to it from the user’s desktop or start menu. This is all enabled within Silverlight without any additional download of runtime or the need to write applications in a different way. An application can now be easily found on the user’s desktop or start menu, and launched with a single click. In addition, it can test if the network is connected, it can update itself, and can also have access to Isolated Storage. Taken together, these features represent a radical upgrade to the web experience.
Synopsis:
can create shortcut from desktop and don't need additional download when start the silverlight application. If network is connected, the application will update itself.
:)
https://www.microsoft.com/silverlight/out-of-browser/
Silverlight offers a new set of features for building light-weight, sandboxed companion experiences for the Web that run on the desktop. Silverlight out of browser allows websites to build even closer, persistent relationships with customers. It enables the application to be placed in a restricted store on the user’s machine; and then provide a link directly to it from the user’s desktop or start menu. This is all enabled within Silverlight without any additional download of runtime or the need to write applications in a different way. An application can now be easily found on the user’s desktop or start menu, and launched with a single click. In addition, it can test if the network is connected, it can update itself, and can also have access to Isolated Storage. Taken together, these features represent a radical upgrade to the web experience.
Synopsis:
can create shortcut from desktop and don't need additional download when start the silverlight application. If network is connected, the application will update itself.
:)
Wednesday, June 24, 2015
how to make grid to show 100% for xaml?
I had a little struggle to archive this, finally found that it is just as simple as setting both HorizontalAlignment and VerticalAlignment = "Stretch".
also if you have separate your grid to 3 column, set your Grid.ColumnSpan="3";
finally, remember to set MinHeight="" and MinWidth="" instead of height n width.
happy coding.
also if you have separate your grid to 3 column, set your Grid.ColumnSpan="3";
finally, remember to set MinHeight="" and MinWidth="" instead of height n width.
happy coding.
Monday, June 22, 2015
string to array, array to string via string builder.
Change comma separated string to array of string.
separate the string with comma into an array.
eg:
private void validateCompanyList()
{
//txtCompany output = "Company1, company2, company3,company4";
string[] companyList = txtCompany.Text.Split(',').ToArray();
if (companyList.Count() > 0)
{
foreach (string company in companyList)
{
//eg: 1st iteration => company = "Company1"
// 2nd: company = " company2"
// 3rd : company = " company3"
// 4th : company = "company4"
//if you take the company.trim(), then you will get
// 1st: company.trim() = "Company1"
// 2nd: company.trim() = "company2"
// 3rd: company.trim() = "company3"
// 4th: company.trim() = "company4"
}
}
}
you can then use stringBuilder to join back the company into a string.
for example:
using System.Text;
private void validateCompanyList()
{
if (string.IsNullOrWhiteSpace(txtCompany.Text))
return;
string[] companyList = txtCompany.Text.Split(',').ToArray();
StringBuilder sbErrorMsg = new StringBuilder();
if (companyList.Count() > 0)
{
foreach (string company in companyList)
{
int found = CompanyObject.Where(t=> t.COMPANY_CODE == company.Trim().ToUpper() && t.REC_DELETED == Constant.RECORD_ACTIVE).Count();
if (found == 0)
{
if (sbErrorMsg.Length != 0)
sbErrorMsg.Append(",");
sbErrorMsg.Append(company.Trim());
}
}
}
if (sbErrorMsg.Length != 0)
{
ErrorMessage.errorMessageControl(string.Concat("Invalid company code(s) : " , sbErrorMsg));
}
}
Beside text.split(','); you can also take a look at text.split(new char[] { ',' }, StringSplitOptions), where you can choose StringSplitOptions.None or StringSplitOptions.RemoveEmptyEntries.
let's take a look at the second option :
string[] companySpliter = txtCompany.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
With this option, the return value doesn't not include array element that is empty string. This is a very good way if you want to exclude null string in array after split.
eg: txtCompany.Text = ",,,,,,";
companySpliter.length is 0 for this case.
while string[] companySpliter2 = txtCompany.Text.Split( ',' );
will have companySpliter2.length equal to 7, with all the child element having string.Empty.
However, StringSplitOptions.RemoveEmptyEntries will not exclude child element that contain only space(s).
eg: txtCompany.Text = " , ";
companySpliter.length is 2 for this case.
same with string[] companySpliter2 = txtCompany.Text.Split( ',' );
which will have companySpliter2.length equal to 2.
You will still need string.IsNullOrWhiteSpace(company) to check while looping the array if you wish to ignore the spaces.
separate the string with comma into an array.
eg:
private void validateCompanyList()
{
//txtCompany output = "Company1, company2, company3,company4";
string[] companyList = txtCompany.Text.Split(',').ToArray();
if (companyList.Count() > 0)
{
foreach (string company in companyList)
{
//eg: 1st iteration => company = "Company1"
// 2nd: company = " company2"
// 3rd : company = " company3"
// 4th : company = "company4"
//if you take the company.trim(), then you will get
// 1st: company.trim() = "Company1"
// 2nd: company.trim() = "company2"
// 3rd: company.trim() = "company3"
// 4th: company.trim() = "company4"
}
}
}
you can then use stringBuilder to join back the company into a string.
for example:
using System.Text;
private void validateCompanyList()
{
if (string.IsNullOrWhiteSpace(txtCompany.Text))
return;
string[] companyList = txtCompany.Text.Split(',').ToArray();
StringBuilder sbErrorMsg = new StringBuilder();
if (companyList.Count() > 0)
{
foreach (string company in companyList)
{
int found = CompanyObject.Where(t=> t.COMPANY_CODE == company.Trim().ToUpper() && t.REC_DELETED == Constant.RECORD_ACTIVE).Count();
if (found == 0)
{
if (sbErrorMsg.Length != 0)
sbErrorMsg.Append(",");
sbErrorMsg.Append(company.Trim());
}
}
}
if (sbErrorMsg.Length != 0)
{
ErrorMessage.errorMessageControl(string.Concat("Invalid company code(s) : " , sbErrorMsg));
}
}
Beside text.split(','); you can also take a look at text.split(new char[] { ',' }, StringSplitOptions), where you can choose StringSplitOptions.None or StringSplitOptions.RemoveEmptyEntries.
let's take a look at the second option :
string[] companySpliter = txtCompany.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
With this option, the return value doesn't not include array element that is empty string. This is a very good way if you want to exclude null string in array after split.
eg: txtCompany.Text = ",,,,,,";
companySpliter.length is 0 for this case.
while string[] companySpliter2 = txtCompany.Text.Split( ',' );
will have companySpliter2.length equal to 7, with all the child element having string.Empty.
However, StringSplitOptions.RemoveEmptyEntries will not exclude child element that contain only space(s).
eg: txtCompany.Text = " , ";
companySpliter.length is 2 for this case.
same with string[] companySpliter2 = txtCompany.Text.Split( ',' );
which will have companySpliter2.length equal to 2.
You will still need string.IsNullOrWhiteSpace(company) to check while looping the array if you wish to ignore the spaces.
Saturday, June 20, 2015
How Scrum can help improve productivity
If you are struggling on whether to go or not for SCRUM, here is an article that you may found worth for a read.
https://www.scrumalliance.org/community/articles/2015/june/why-scrum
if you are wandering how can SCRUM help my organization, this article may give you some hints.
https://www.scrumalliance.org/community/articles/2015/june/why-scrum
if you are wandering how can SCRUM help my organization, this article may give you some hints.
Friday, June 19, 2015
IsNullOrEmpty better or IsNullOrWhiteSpace better?
IsNullOrEmpty vs IsNullOrWhiteSpace
Are you also thinking , is IsNullOrEmpty better or IsNullOrWhiteSpace better?
The answer is IsNullOrWhiteSpace, unless you want to accept space (" ") or spaces(" ") as valid input.
The reason is IsNullOrWhiteSpace will validate (" ") as true, while IsNullOrEmpty required you to trim the string inorder to validate it the empty space. If you trim a string that is null, you will get exception.
Before the introduce of IsNullOrWhiteSpace , the usual way checking might be:
if(!string.IsNullOrEmpty(stringA))
if (stringA.Trim().Length != "")
dataSavingForExample;
IsNullOrWhiteSpace : lesser code, safer for empty space checking and better performance. :)
Are you also thinking , is IsNullOrEmpty better or IsNullOrWhiteSpace better?
The answer is IsNullOrWhiteSpace, unless you want to accept space (" ") or spaces(" ") as valid input.
The reason is IsNullOrWhiteSpace will validate (" ") as true, while IsNullOrEmpty required you to trim the string inorder to validate it the empty space. If you trim a string that is null, you will get exception.
Before the introduce of IsNullOrWhiteSpace , the usual way checking might be:
if(!string.IsNullOrEmpty(stringA))
if (stringA.Trim().Length != "")
dataSavingForExample;
IsNullOrWhiteSpace : lesser code, safer for empty space checking and better performance. :)
Subscribe to:
Comments (Atom)